@deriv-com/analytics
Version:
The analytics package contains all the utility functions used for tracking user events and sending them to the respective platform such as Rudderstack.
54 lines (53 loc) • 2.55 kB
TypeScript
import { RudderAnalytics } from '@rudderstack/analytics-js';
import { TCoreAttributes, TEvents } from './types';
export declare class RudderStack {
analytics: RudderAnalytics;
has_identified: boolean;
has_initialized: boolean;
current_page: string;
rudderstack_anonymous_cookie_key: string;
private static _instance;
private onLoadedCallback?;
constructor(RUDDERSTACK_KEY: string, disableAMD?: boolean, onLoaded?: () => void);
static getRudderStackInstance: (RUDDERSTACK_KEY: string, disableAMD?: boolean, onLoaded?: () => void) => RudderStack;
getAnonymousId: () => string | undefined;
setCookieIfNotExists: () => void;
/**
* @returns The user ID that was assigned to the user after calling identify event
*/
getUserId: () => (string | null) | undefined;
/** For caching mechanism, Rudderstack SDK, first page load */
handleCachedEvents: () => void;
/**
* Initializes the Rudderstack SDK. Ensure that the appropriate environment variables are set before this is called.
* For local/staging environment, ensure that `RUDDERSTACK_STAGING_KEY` and `RUDDERSTACK_URL` is set.
* For production environment, ensure that `RUDDERSTACK_PRODUCTION_KEY` and `RUDDERSTACK_URL` is set.
*/
init: (RUDDERSTACK_KEY: string, disableAMD?: boolean) => void;
/**
*
* @param user_id The user ID of the user to identify and associate all events with that particular user ID
* @param payload Additional information passed to identify the user
*/
identifyEvent: (user_id: string, payload: {
language: string;
}) => void;
/**
* Pushes page view event to Rudderstack
*
* @param curret_page The name or URL of the current page to track the page view event
*/
pageView: (current_page: string, platform: string | undefined, user_id: string, properties?: {}) => void;
/**
* Pushes reset event to rudderstack
*/
reset: () => void;
/**
* Pushes track events to Rudderstack. When this method is called before `identifyEvent` method is called, the events tracked will be associated with an anonymous ID.
* Otherwise, if the events needs to be associated with a user ID, call `identifyEvent` with the user ID passed first before calling this method.
*
* @param event The event name to track
* @param payload Additional information related to the event
*/
track: <T extends keyof TEvents>(event: T, payload: TEvents[T] & Partial<TCoreAttributes>) => void;
}