@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.
50 lines (49 loc) • 2.2 kB
TypeScript
import { RudderAnalytics } from '@rudderstack/analytics-js';
import { TCoreAttributes, TAllEvents } 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.
*/
track: <T extends keyof import("./types").TEvents | "ce_get_start_page">(event: T, payload: TAllEvents[T] & Partial<TCoreAttributes>) => void;
}