npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@deriv-com/analytics

v1.5.3

Published

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

Downloads

9,582

Readme

@deriv-com/analytics

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

In this document

What is Analytics?

Cross-project, connected user tracking events with A/B testing features

Installation

To install the package, run the following command:

$ npm i @deriv-com/analytics

To proper initialisation of the package, pass proper keys in special function in special for init functions place:

Analytics?.initialise({
    growthbookKey: process.env.GROWTHBOOK_CLIENT_KEY, // optional key to enable A/B tests
    growthbookDecryptionKey: process.env.GROWTHBOOK_DECRYPTION_KEY, // optional key to enable A/B tests
    // mandatory key to enable userevent tracking
    rudderstackKey: RUDDERSTACK_KEY,

    growthbookOptions: {
        // optional options for overriding growthbook default options
        // if you want e.g
        antiFlicker: false,
        navigateDelay: 0,
        antiFlickerTimeout: 3500,
        subscribeToChanges: true,
        enableDevMode: window?.location.hostname.includes('localhost'),
        trackingCallback: (experiment, result) => {
            console.log('Tracking callback', experiment, result)
        }
        navigate: (url) => window.location.href = url,
    }
})

To make good strategy for A/B testing we need to create some condition depends on data:

Analytics?.setAttributes({
    user_language: getLanguage(),
    device_language: navigator?.language,
    country: this.country,
})

And you finally can use the tracking events and A/B testing features

Usage

To start using it, let's observe on SDK usage examples:

import { Analytics } from '@deriv-com/analytics';

// Tracking features:
Analytics?.identifyEvent() // inentify the user
Analytics?.pageView() // track that page is showed for user
const user_id = Analytics?.getId() // get an user anon or real id


// Track Event
Analytics?.trackEvent('ce_virtual_signup_form', {
    action: 'open',
    form_name: 'default_diel_deriv',
    form_source: document?.referrer,
    signup_provider: 'email',
})

// the same as example below, to not to add repetable properties again and again
const analytics_data: Parameters<typeof Analytics.trackEvent>[1] = {
    form_name: 'default_diel_deriv',
}
Analytics?.trackEvent('ce_virtual_signup_form', {
    action: 'open',
    signup_provider: 'email',
    ...analytics_data
})
Analytics?.trackEvent('ce_virtual_signup_form', {
    action: 'close',
    signup_provider: 'google',
    ...analytics_data
})

// A/B testing features
const test_toggle_aa_test = Analytics?.getFeatureState('test-toggle-aa-test') // returns value of experiment
const common_test = Analytics?.getFeatureValue('common-test', 'fallback') // returns feature flag's boolen

If you need to get entire instance directly:

const { ab, tracking } = Analytics?.getInstances()

If you want to check your ID

window.getMyId()