Coder Social home page Coder Social logo

deriv-analytics's Introduction

@deriv/analytics

The analytics package contains all the utility functions used for tracking user events and sending them to the respective platform such as Rudderstack.

In this document

RudderStack

What is RudderStack?

RudderStack is a platform that allows you to easily connect different analytical tools and applications such as Google Analytics, and send data and events to the respective tool/application that requires it. Events sent to RudderStack will be routed to the respective tool and application, similar to a reverse proxy but for data and analytics.

Installation

To install the package, run the following command:

$ npm i @deriv/analytics

After installing the package, ensure that the correct workflow is triggered when installing a new dependency. This varies between different projects, thus refer to the project's respective documentation for more details on installing a new dependency.

Usage

To start using it, import the SDK by calling (ensure that the camelcase spelling is correct, it is Rudder Stack not Rudder stack). The RudderStack SDK will be automatically instantiated and loaded when importing it:

import { RudderStack } from '@deriv/analytics';

If the environment is either staging or production, the RudderStack SDK instance will be automatically created and initialized, provided that the environment variable keys RUDDERSTACK_STAGING_KEY, RUDDERSTACK_PRODUCTION_KEY and RUDDERSTACK_URL has been set. To start using it in a development environment, make sure the following environment variables are set locally:

CIRCLE_JOB=release_staging
RUDDERSTACK_STAGING_KEY=...
RUDDERSTACK_URL=...

Tracking authenticated users

To start tracking users that has been authenticated, begin by calling RudderStack.identifyEvent and providing the user's ID as well as any additional information such as the language of the platform:

RudderStack.identifyEvent('CR90000438', {
    language: 'EN',
});

This event is recommended to be called after the websocket returns an authorize response.

Once identifyEvent has been called, events sent using RudderStack.track will be tracked and associated to the authenticated user by their ID. Note that at the moment, the RudderStack implementation only tracks authenticated users and not users who have not logged in. So in order to start tracking, the user must be identified first using identifyEvent.

API Reference

identifyEvent

Rudderstack.identifyEvent(user_id, payload);
Parameter Type Description
user_id string The users' login ID
payload { language: string } Contains user's session details such as the platform language they are currently in

Identifies the user to Rudderstack and associates all events tracked to the user. For example:

Rudderstack.identifyEvent('C123456', {
    language: 'EN',
});

pageView

Rudderstack.pageView(current_page);
Parameter Type Description
current_page string The name of the page to track

Tracks the current page view. For example:

Rudderstack.pageView('Deriv.app');

track

Rudderstack.track(event, payload);
Parameter Type Description
event string type with one of these events:
- ce_virtual_signup_form
- ce_real_account_signup_form
- ce_virtual_signup_email_confirmation
- ce_trade_types_form
The name of the event to track
payload object The properties and data associated with the event

For example, to track the event ce_trade_types_form for the action search:

Rudderstack.track('ce_trade_types_form', {
    action: 'search',
    search_string: 'What are multipliers',
});

deriv-analytics's People

Contributors

amir-deriv avatar nikitk-deriv avatar ali-hosseini-deriv avatar adrienne-deriv avatar lipika-deriv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.