@deriv-com/analytics 1.4.12 → 1.5.0-beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,31 +1,23 @@
1
- import { Growthbook } from './growthbook';
1
+ import type { Context } from '@growthbook/growthbook';
2
+ import { Growthbook, GrowthbookConfigs } from './growthbook';
2
3
  import { RudderStack } from './rudderstack';
3
4
  import { TCoreAttributes, TEvents } from './types';
4
5
  type Options = {
5
6
  growthbookKey?: string;
7
+ growthbookOptions?: Partial<Context>;
6
8
  growthbookDecryptionKey?: string;
7
9
  rudderstackKey: string;
8
10
  };
9
11
  export declare function createAnalyticsInstance(options?: Options): {
10
- initialise: ({ growthbookKey, growthbookDecryptionKey, rudderstackKey }: Options) => void;
12
+ initialise: ({ growthbookKey, growthbookDecryptionKey, rudderstackKey, growthbookOptions }: Options) => void;
11
13
  setAttributes: ({ country, user_language, device_language, device_type, account_type, user_id, app_id, utm_source, utm_medium, utm_campaign, is_authorised, }: TCoreAttributes) => void;
12
14
  identifyEvent: () => void;
13
15
  getFeatureState: (id: string) => string | undefined;
14
- getFeatureValue: <T>(id: string, defaultValue?: T | undefined) => boolean | ((attributes: import("@growthbook/growthbook").Attributes) => void) | ((options?: import("@growthbook/growthbook").LoadFeaturesOptions | undefined) => Promise<void>) | ((options?: import("@growthbook/growthbook").RefreshFeaturesOptions | undefined) => Promise<void>) | (() => [string, string]) | (() => {
15
- apiHost: string;
16
- streamingHost: string;
17
- apiRequestHeaders?: Record<string, string> | undefined;
18
- streamingHostRequestHeaders?: Record<string, string> | undefined;
19
- }) | (() => string) | (() => boolean) | (() => string[] | undefined) | ((features: Record<string, import("@growthbook/growthbook").FeatureDefinition<any>>) => void) | ((encryptedString: string, decryptionKey?: string | undefined, subtle?: SubtleCrypto | undefined) => Promise<void>) | ((experiments: import("@growthbook/growthbook").AutoExperiment[]) => void) | ((encryptedString: string, decryptionKey?: string | undefined, subtle?: SubtleCrypto | undefined) => Promise<void>) | ((overrides: import("@growthbook/growthbook").Attributes) => void) | ((vars: Record<string, number>) => void) | ((map: Map<string, any>) => void) | ((url: string) => void) | (() => {
20
- [x: string]: any;
21
- }) | (() => Record<string, number>) | (() => Map<string, any>) | (() => string) | (() => Record<string, import("@growthbook/growthbook").FeatureDefinition<any>>) | (() => import("@growthbook/growthbook").AutoExperiment[]) | ((cb: import("@growthbook/growthbook").SubscriptionFunction) => () => void) | (() => Map<string, {
22
- experiment: import("@growthbook/growthbook").Experiment<any>;
23
- result: import("@growthbook/growthbook").Result<any>;
24
- }>) | (() => void) | ((renderer: () => void) => void) | ((key: string, variation: number) => void) | (<T_1>(experiment: import("@growthbook/growthbook").Experiment<T_1>) => import("@growthbook/growthbook").Result<T_1>) | ((key: string) => import("@growthbook/growthbook").Result<import("@growthbook/growthbook").AutoExperimentVariation> | null) | (<K extends string = string>(key: K) => boolean) | (<K_1 extends string = string>(key: K_1) => boolean) | (<V extends any, K_2 extends string = string>(key: K_2, defaultValue: V) => import("@growthbook/growthbook").WidenPrimitives<V>) | (<V_1 extends any, K_3 extends string = string>(id: K_3) => import("@growthbook/growthbook").FeatureResult<V_1 | null>) | (<V_2 extends any, K_4 extends string = string>(id: K_4) => import("@growthbook/growthbook").FeatureResult<V_2 | null>) | ((msg: string, ctx: Record<string, unknown>) => void);
16
+ getFeatureValue: <K extends string | number, V extends GrowthbookConfigs[K]>(id: K, defaultValue: V) => import("@growthbook/growthbook").WidenPrimitives<V>;
25
17
  isFeatureOn: (key: string) => boolean;
26
- setUrl: (href: string) => void;
18
+ setUrl: (href: string) => Promise<void>;
27
19
  getId: () => string;
28
- trackEvent: <T_2 extends keyof TEvents>(event: T_2, analytics_data: TEvents[T_2]) => void;
20
+ trackEvent: <T extends keyof TEvents>(event: T, analytics_data: TEvents[T]) => void;
29
21
  getInstances: () => {
30
22
  ab: Growthbook;
31
23
  tracking: RudderStack;
@@ -34,25 +26,15 @@ export declare function createAnalyticsInstance(options?: Options): {
34
26
  reset: () => void;
35
27
  };
36
28
  export declare const Analytics: {
37
- initialise: ({ growthbookKey, growthbookDecryptionKey, rudderstackKey }: Options) => void;
29
+ initialise: ({ growthbookKey, growthbookDecryptionKey, rudderstackKey, growthbookOptions }: Options) => void;
38
30
  setAttributes: ({ country, user_language, device_language, device_type, account_type, user_id, app_id, utm_source, utm_medium, utm_campaign, is_authorised, }: TCoreAttributes) => void;
39
31
  identifyEvent: () => void;
40
32
  getFeatureState: (id: string) => string | undefined;
41
- getFeatureValue: <T>(id: string, defaultValue?: T | undefined) => boolean | ((attributes: import("@growthbook/growthbook").Attributes) => void) | ((options?: import("@growthbook/growthbook").LoadFeaturesOptions | undefined) => Promise<void>) | ((options?: import("@growthbook/growthbook").RefreshFeaturesOptions | undefined) => Promise<void>) | (() => [string, string]) | (() => {
42
- apiHost: string;
43
- streamingHost: string;
44
- apiRequestHeaders?: Record<string, string> | undefined;
45
- streamingHostRequestHeaders?: Record<string, string> | undefined;
46
- }) | (() => string) | (() => boolean) | (() => string[] | undefined) | ((features: Record<string, import("@growthbook/growthbook").FeatureDefinition<any>>) => void) | ((encryptedString: string, decryptionKey?: string | undefined, subtle?: SubtleCrypto | undefined) => Promise<void>) | ((experiments: import("@growthbook/growthbook").AutoExperiment[]) => void) | ((encryptedString: string, decryptionKey?: string | undefined, subtle?: SubtleCrypto | undefined) => Promise<void>) | ((overrides: import("@growthbook/growthbook").Attributes) => void) | ((vars: Record<string, number>) => void) | ((map: Map<string, any>) => void) | ((url: string) => void) | (() => {
47
- [x: string]: any;
48
- }) | (() => Record<string, number>) | (() => Map<string, any>) | (() => string) | (() => Record<string, import("@growthbook/growthbook").FeatureDefinition<any>>) | (() => import("@growthbook/growthbook").AutoExperiment[]) | ((cb: import("@growthbook/growthbook").SubscriptionFunction) => () => void) | (() => Map<string, {
49
- experiment: import("@growthbook/growthbook").Experiment<any>;
50
- result: import("@growthbook/growthbook").Result<any>;
51
- }>) | (() => void) | ((renderer: () => void) => void) | ((key: string, variation: number) => void) | (<T_1>(experiment: import("@growthbook/growthbook").Experiment<T_1>) => import("@growthbook/growthbook").Result<T_1>) | ((key: string) => import("@growthbook/growthbook").Result<import("@growthbook/growthbook").AutoExperimentVariation> | null) | (<K extends string = string>(key: K) => boolean) | (<K_1 extends string = string>(key: K_1) => boolean) | (<V extends any, K_2 extends string = string>(key: K_2, defaultValue: V) => import("@growthbook/growthbook").WidenPrimitives<V>) | (<V_1 extends any, K_3 extends string = string>(id: K_3) => import("@growthbook/growthbook").FeatureResult<V_1 | null>) | (<V_2 extends any, K_4 extends string = string>(id: K_4) => import("@growthbook/growthbook").FeatureResult<V_2 | null>) | ((msg: string, ctx: Record<string, unknown>) => void);
33
+ getFeatureValue: <K extends string | number, V extends GrowthbookConfigs[K]>(id: K, defaultValue: V) => import("@growthbook/growthbook").WidenPrimitives<V>;
52
34
  isFeatureOn: (key: string) => boolean;
53
- setUrl: (href: string) => void;
35
+ setUrl: (href: string) => Promise<void>;
54
36
  getId: () => string;
55
- trackEvent: <T_2 extends keyof TEvents>(event: T_2, analytics_data: TEvents[T_2]) => void;
37
+ trackEvent: <T extends keyof TEvents>(event: T, analytics_data: TEvents[T]) => void;
56
38
  getInstances: () => {
57
39
  ab: Growthbook;
58
40
  tracking: RudderStack;
package/lib/analytics.js CHANGED
@@ -15,25 +15,25 @@ exports.Analytics = exports.createAnalyticsInstance = void 0;
15
15
  var growthbook_1 = require("./growthbook");
16
16
  var rudderstack_1 = require("./rudderstack");
17
17
  function createAnalyticsInstance(options) {
18
- var _growthbook, _rudderstack, core_data = {}, cta_buttons = {}, offline_cache = {};
19
- var interval = setInterval(function () {
20
- if (Object.keys(cta_buttons).length > 0)
21
- clearInterval(interval);
22
- else
23
- cta_buttons = getFeatureValue('tracking-buttons-config', {});
24
- }, 1000);
18
+ var _growthbook, _rudderstack, core_data = {}, tracking_config = {}, offline_cache = {};
25
19
  var initialise = function (_a) {
26
- var growthbookKey = _a.growthbookKey, growthbookDecryptionKey = _a.growthbookDecryptionKey, rudderstackKey = _a.rudderstackKey;
20
+ var growthbookKey = _a.growthbookKey, growthbookDecryptionKey = _a.growthbookDecryptionKey, rudderstackKey = _a.rudderstackKey, growthbookOptions = _a.growthbookOptions;
27
21
  _rudderstack = rudderstack_1.RudderStack.getRudderStackInstance(rudderstackKey);
28
22
  if (growthbookKey && growthbookDecryptionKey) {
29
- _growthbook = growthbook_1.Growthbook.getGrowthBookInstance(growthbookKey, growthbookDecryptionKey);
23
+ _growthbook = growthbook_1.Growthbook.getGrowthBookInstance(growthbookKey, growthbookDecryptionKey, growthbookOptions);
24
+ var interval_1 = setInterval(function () {
25
+ if (Object.keys(tracking_config).length > 0)
26
+ clearInterval(interval_1);
27
+ else
28
+ tracking_config = getFeatureValue('tracking-buttons-config', {});
29
+ }, 1000);
30
30
  }
31
31
  };
32
32
  var setAttributes = function (_a) {
33
33
  var country = _a.country, user_language = _a.user_language, device_language = _a.device_language, device_type = _a.device_type, account_type = _a.account_type, user_id = _a.user_id, app_id = _a.app_id, utm_source = _a.utm_source, utm_medium = _a.utm_medium, utm_campaign = _a.utm_campaign, is_authorised = _a.is_authorised;
34
34
  if (!_growthbook && !_rudderstack)
35
35
  return;
36
- var user_identity = user_id ? user_id : getId();
36
+ var user_identity = user_id !== null && user_id !== void 0 ? user_id : getId();
37
37
  // Check if we have Growthbook instance
38
38
  if (_growthbook) {
39
39
  _growthbook.setAttributes({
@@ -81,14 +81,13 @@ function createAnalyticsInstance(options) {
81
81
  return;
82
82
  if (navigator.onLine) {
83
83
  if (Object.keys(offline_cache).length > 0) {
84
- Object.keys(offline_cache).map(function (cache) {
84
+ Object.keys(offline_cache).forEach(function (cache) {
85
85
  _rudderstack.track(offline_cache[cache].event, offline_cache[cache].payload);
86
86
  delete offline_cache[cache];
87
87
  });
88
88
  }
89
- if (event in cta_buttons) {
90
- // @ts-ignore
91
- cta_buttons[event] && (_rudderstack === null || _rudderstack === void 0 ? void 0 : _rudderstack.track(event, __assign(__assign({}, core_data), analytics_data)));
89
+ if (event in tracking_config) {
90
+ tracking_config[event] && (_rudderstack === null || _rudderstack === void 0 ? void 0 : _rudderstack.track(event, __assign(__assign({}, core_data), analytics_data)));
92
91
  }
93
92
  else
94
93
  _rudderstack === null || _rudderstack === void 0 ? void 0 : _rudderstack.track(event, __assign(__assign({}, core_data), analytics_data));
@@ -1,34 +1,19 @@
1
- import { GrowthBook } from '@growthbook/growthbook';
1
+ import { Context, GrowthBook } from '@growthbook/growthbook';
2
2
  import { TGrowthbookAttributes } from './types';
3
+ export type GrowthbookConfigs = {
4
+ 'tracking-buttons-config': Record<string, boolean>;
5
+ } & {
6
+ [key: string]: Record<string, boolean> | string | boolean | [];
7
+ };
3
8
  export declare class Growthbook {
4
- GrowthBook: GrowthBook<GrowthBook<Record<string, any>>>;
9
+ GrowthBook: GrowthBook<GrowthbookConfigs>;
5
10
  private static _instance;
6
- constructor(clientKey: string, decryptionKey: string);
7
- static getGrowthBookInstance(clientKey: string, decryptionKey: string): Growthbook;
8
- setAttributes({ id, country, user_language, device_language, device_type, utm_source, utm_medium, utm_campaign, is_authorised, }: TGrowthbookAttributes): void;
9
- getFeatureState<K, V>(id: K): import("@growthbook/growthbook").FeatureResult<boolean | ((attributes: import("@growthbook/growthbook").Attributes) => void) | ((options?: import("@growthbook/growthbook").LoadFeaturesOptions | undefined) => Promise<void>) | ((options?: import("@growthbook/growthbook").RefreshFeaturesOptions | undefined) => Promise<void>) | (() => [string, string]) | (() => {
10
- apiHost: string;
11
- streamingHost: string;
12
- apiRequestHeaders?: Record<string, string> | undefined;
13
- streamingHostRequestHeaders?: Record<string, string> | undefined;
14
- }) | (() => string) | (() => boolean) | (() => string[] | undefined) | ((features: Record<string, import("@growthbook/growthbook").FeatureDefinition<any>>) => void) | ((encryptedString: string, decryptionKey?: string | undefined, subtle?: SubtleCrypto | undefined) => Promise<void>) | ((experiments: import("@growthbook/growthbook").AutoExperiment[]) => void) | ((encryptedString: string, decryptionKey?: string | undefined, subtle?: SubtleCrypto | undefined) => Promise<void>) | ((overrides: import("@growthbook/growthbook").Attributes) => void) | ((vars: Record<string, number>) => void) | ((map: Map<string, any>) => void) | ((url: string) => void) | (() => {
15
- [x: string]: any;
16
- }) | (() => Record<string, number>) | (() => Map<string, any>) | (() => string) | (() => Record<string, import("@growthbook/growthbook").FeatureDefinition<any>>) | (() => import("@growthbook/growthbook").AutoExperiment[]) | ((cb: import("@growthbook/growthbook").SubscriptionFunction) => () => void) | (() => Map<string, {
17
- experiment: import("@growthbook/growthbook").Experiment<any>;
18
- result: import("@growthbook/growthbook").Result<any>;
19
- }>) | (() => void) | ((renderer: () => void) => void) | ((key: string, variation: number) => void) | (<T>(experiment: import("@growthbook/growthbook").Experiment<T>) => import("@growthbook/growthbook").Result<T>) | ((key: string) => import("@growthbook/growthbook").Result<import("@growthbook/growthbook").AutoExperimentVariation> | null) | (<K_1 extends string = string>(key: K_1) => boolean) | (<K_2 extends string = string>(key: K_2) => boolean) | (<V_1 extends any, K_3 extends string = string>(key: K_3, defaultValue: V_1) => import("@growthbook/growthbook").WidenPrimitives<V_1>) | (<V_2 extends any, K_4 extends string = string>(id: K_4) => import("@growthbook/growthbook").FeatureResult<V_2 | null>) | (<V_3 extends any, K_5 extends string = string>(id: K_5) => import("@growthbook/growthbook").FeatureResult<V_3 | null>) | ((msg: string, ctx: Record<string, unknown>) => void) | null>;
20
- getFeatureValue<K, V>(key: K, defaultValue?: V): boolean | ((attributes: import("@growthbook/growthbook").Attributes) => void) | ((options?: import("@growthbook/growthbook").LoadFeaturesOptions | undefined) => Promise<void>) | ((options?: import("@growthbook/growthbook").RefreshFeaturesOptions | undefined) => Promise<void>) | (() => [string, string]) | (() => {
21
- apiHost: string;
22
- streamingHost: string;
23
- apiRequestHeaders?: Record<string, string> | undefined;
24
- streamingHostRequestHeaders?: Record<string, string> | undefined;
25
- }) | (() => string) | (() => boolean) | (() => string[] | undefined) | ((features: Record<string, import("@growthbook/growthbook").FeatureDefinition<any>>) => void) | ((encryptedString: string, decryptionKey?: string | undefined, subtle?: SubtleCrypto | undefined) => Promise<void>) | ((experiments: import("@growthbook/growthbook").AutoExperiment[]) => void) | ((encryptedString: string, decryptionKey?: string | undefined, subtle?: SubtleCrypto | undefined) => Promise<void>) | ((overrides: import("@growthbook/growthbook").Attributes) => void) | ((vars: Record<string, number>) => void) | ((map: Map<string, any>) => void) | ((url: string) => void) | (() => {
26
- [x: string]: any;
27
- }) | (() => Record<string, number>) | (() => Map<string, any>) | (() => string) | (() => Record<string, import("@growthbook/growthbook").FeatureDefinition<any>>) | (() => import("@growthbook/growthbook").AutoExperiment[]) | ((cb: import("@growthbook/growthbook").SubscriptionFunction) => () => void) | (() => Map<string, {
28
- experiment: import("@growthbook/growthbook").Experiment<any>;
29
- result: import("@growthbook/growthbook").Result<any>;
30
- }>) | (() => void) | ((renderer: () => void) => void) | ((key: string, variation: number) => void) | (<T>(experiment: import("@growthbook/growthbook").Experiment<T>) => import("@growthbook/growthbook").Result<T>) | ((key: string) => import("@growthbook/growthbook").Result<import("@growthbook/growthbook").AutoExperimentVariation> | null) | (<K_1 extends string = string>(key: K_1) => boolean) | (<K_2 extends string = string>(key: K_2) => boolean) | (<V_1 extends any, K_3 extends string = string>(key: K_3, defaultValue: V_1) => import("@growthbook/growthbook").WidenPrimitives<V_1>) | (<V_2 extends any, K_4 extends string = string>(id: K_4) => import("@growthbook/growthbook").FeatureResult<V_2 | null>) | (<V_3 extends any, K_5 extends string = string>(id: K_5) => import("@growthbook/growthbook").FeatureResult<V_3 | null>) | ((msg: string, ctx: Record<string, unknown>) => void);
31
- setUrl(href: string): void;
32
- isOn(key: string): boolean;
33
- init(): void;
11
+ constructor(clientKey: string, decryptionKey: string, settings?: Partial<Context>);
12
+ static getGrowthBookInstance: (clientKey: string, decryptionKey: string, growthbookOptions?: Partial<Context>) => Growthbook;
13
+ setAttributes: ({ id, country, user_language, device_language, device_type, utm_source, utm_medium, utm_campaign, is_authorised, }: TGrowthbookAttributes) => void;
14
+ getFeatureValue: <K extends string | number, V extends GrowthbookConfigs[K]>(key: K, defaultValue: V) => import("@growthbook/growthbook").WidenPrimitives<V>;
15
+ getFeatureState: (id: string) => import("@growthbook/growthbook").FeatureResult<string | boolean | Record<string, boolean> | [] | null>;
16
+ setUrl: (href: string) => Promise<void>;
17
+ isOn: (key: string) => boolean;
18
+ init: () => Promise<void>;
34
19
  }
package/lib/growthbook.js CHANGED
@@ -39,14 +39,21 @@ var growthbook_1 = require("@growthbook/growthbook");
39
39
  var RudderAnalytics = __importStar(require("rudder-sdk-js"));
40
40
  var Growthbook = /** @class */ (function () {
41
41
  // we have to pass settings due the specific framework implementation
42
- function Growthbook(clientKey, decryptionKey) {
43
- this.GrowthBook = new growthbook_1.GrowthBook({
44
- apiHost: 'https://cdn.growthbook.io',
45
- clientKey: clientKey,
46
- decryptionKey: decryptionKey,
47
- subscribeToChanges: true,
48
- enableDevMode: window === null || window === void 0 ? void 0 : window.location.hostname.includes('localhost'),
49
- trackingCallback: function (experiment, result) {
42
+ function Growthbook(clientKey, decryptionKey, settings) {
43
+ if (settings === void 0) { settings = {}; }
44
+ var _this = this;
45
+ this.setAttributes = function (_a) {
46
+ var id = _a.id, country = _a.country, user_language = _a.user_language, device_language = _a.device_language, device_type = _a.device_type, utm_source = _a.utm_source, utm_medium = _a.utm_medium, utm_campaign = _a.utm_campaign, is_authorised = _a.is_authorised;
47
+ _this.GrowthBook.setAttributes(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({ id: id }, (country !== undefined && { country: country })), (user_language !== undefined && { user_language: user_language })), (device_language !== undefined && { device_language: device_language })), (device_type !== undefined && { device_type: device_type })), (utm_source !== undefined && { utm_source: utm_source })), (utm_medium !== undefined && { utm_medium: utm_medium })), (utm_campaign !== undefined && { utm_campaign: utm_campaign })), (is_authorised !== undefined && { is_authorised: is_authorised })));
48
+ };
49
+ this.getFeatureValue = function (key, defaultValue) {
50
+ return _this.GrowthBook.getFeatureValue(key, defaultValue);
51
+ };
52
+ this.getFeatureState = function (id) { return _this.GrowthBook.evalFeature(id); };
53
+ this.setUrl = function (href) { return _this.GrowthBook.setURL(href); };
54
+ this.isOn = function (key) { return _this.GrowthBook.isOn(key); };
55
+ this.init = function () { return _this.GrowthBook.loadFeatures().catch(function (err) { return console.error(err); }); };
56
+ this.GrowthBook = new growthbook_1.GrowthBook(__assign({ apiHost: 'https://cdn.growthbook.io', clientKey: clientKey, decryptionKey: decryptionKey, antiFlicker: true, navigateDelay: 0, antiFlickerTimeout: 3500, subscribeToChanges: true, enableDevMode: window === null || window === void 0 ? void 0 : window.location.hostname.includes('localhost'), trackingCallback: function (experiment, result) {
50
57
  if (window.dataLayer) {
51
58
  window.dataLayer.push({
52
59
  event: 'experiment_viewed',
@@ -60,40 +67,17 @@ var Growthbook = /** @class */ (function () {
60
67
  experimentId: experiment.key,
61
68
  variationId: result.variationId,
62
69
  });
63
- },
64
- });
70
+ } }, settings));
65
71
  this.init();
66
72
  }
67
73
  // for make instance by singleton
68
- Growthbook.getGrowthBookInstance = function (clientKey, decryptionKey) {
74
+ Growthbook.getGrowthBookInstance = function (clientKey, decryptionKey, growthbookOptions) {
69
75
  if (!Growthbook._instance) {
70
- Growthbook._instance = new Growthbook(clientKey, decryptionKey);
76
+ Growthbook._instance = new Growthbook(clientKey, decryptionKey, growthbookOptions);
71
77
  return Growthbook._instance;
72
78
  }
73
79
  return Growthbook._instance;
74
80
  };
75
- Growthbook.prototype.setAttributes = function (_a) {
76
- var id = _a.id, country = _a.country, user_language = _a.user_language, device_language = _a.device_language, device_type = _a.device_type, utm_source = _a.utm_source, utm_medium = _a.utm_medium, utm_campaign = _a.utm_campaign, is_authorised = _a.is_authorised;
77
- return this.GrowthBook.setAttributes(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({ id: id }, (country !== undefined && { country: country })), (user_language !== undefined && { user_language: user_language })), (device_language !== undefined && { device_language: device_language })), (device_type !== undefined && { device_type: device_type })), (utm_source !== undefined && { utm_source: utm_source })), (utm_medium !== undefined && { utm_medium: utm_medium })), (utm_campaign !== undefined && { utm_campaign: utm_campaign })), (is_authorised !== undefined && { is_authorised: is_authorised })));
78
- };
79
- Growthbook.prototype.getFeatureState = function (id) {
80
- // @ts-ignore
81
- return this.GrowthBook.evalFeature(id);
82
- };
83
- Growthbook.prototype.getFeatureValue = function (key, defaultValue) {
84
- // @ts-ignore
85
- return this.GrowthBook.getFeatureValue(key, defaultValue);
86
- };
87
- Growthbook.prototype.setUrl = function (href) {
88
- return this.GrowthBook.setURL(href);
89
- };
90
- Growthbook.prototype.isOn = function (key) {
91
- // @ts-ignore
92
- return this.GrowthBook.isOn(key);
93
- };
94
- Growthbook.prototype.init = function () {
95
- this.GrowthBook.loadFeatures().catch(function (err) { return console.error(err); });
96
- };
97
81
  return Growthbook;
98
82
  }());
99
83
  exports.Growthbook = Growthbook;
@@ -1,25 +1,25 @@
1
- import { TEvents } from './types';
1
+ import { TCoreAttributes, TEvents } from './types';
2
2
  export declare class RudderStack {
3
3
  has_identified: boolean;
4
4
  has_initialized: boolean;
5
5
  current_page: string;
6
6
  private static _instance;
7
7
  constructor(RUDDERSTACK_KEY: string);
8
- static getRudderStackInstance(RUDDERSTACK_KEY: string): RudderStack;
8
+ static getRudderStackInstance: (RUDDERSTACK_KEY: string) => RudderStack;
9
9
  /**
10
10
  * @returns The anonymous ID assigned to the user before the identify event was called
11
11
  */
12
- getAnonymousId(): string;
12
+ getAnonymousId: () => string;
13
13
  /**
14
14
  * @returns The user ID that was assigned to the user after calling identify event
15
15
  */
16
- getUserId(): string;
16
+ getUserId: () => string;
17
17
  /**
18
18
  * Initializes the Rudderstack SDK. Ensure that the appropriate environment variables are set before this is called.
19
19
  * For local/staging environment, ensure that `RUDDERSTACK_STAGING_KEY` and `RUDDERSTACK_URL` is set.
20
20
  * For production environment, ensure that `RUDDERSTACK_PRODUCTION_KEY` and `RUDDERSTACK_URL` is set.
21
21
  */
22
- init(RUDDERSTACK_KEY: string): void;
22
+ init: (RUDDERSTACK_KEY: string) => void;
23
23
  /**
24
24
  *
25
25
  * @param user_id The user ID of the user to identify and associate all events with that particular user ID
@@ -33,11 +33,11 @@ export declare class RudderStack {
33
33
  *
34
34
  * @param curret_page The name or URL of the current page to track the page view event
35
35
  */
36
- pageView(current_page: string, platform: string | undefined, user_id: string): void;
36
+ pageView: (current_page: string, platform: string | undefined, user_id: string) => void;
37
37
  /**
38
38
  * Pushes reset event to rudderstack
39
39
  */
40
- reset(): void;
40
+ reset: () => void;
41
41
  /**
42
42
  * 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.
43
43
  * Otherwise, if the events needs to be associated with a user ID, call `identifyEvent` with the user ID passed first before calling this method.
@@ -45,5 +45,5 @@ export declare class RudderStack {
45
45
  * @param event The event name to track
46
46
  * @param payload Additional information related to the event
47
47
  */
48
- track<T extends keyof TEvents>(event: T, payload: TEvents[T]): void;
48
+ track: <T extends keyof TEvents>(event: T, payload: TEvents[T] & Partial<TCoreAttributes>) => void;
49
49
  }
@@ -31,6 +31,28 @@ var RudderStack = /** @class */ (function () {
31
31
  this.has_identified = false;
32
32
  this.has_initialized = false;
33
33
  this.current_page = '';
34
+ /**
35
+ * @returns The anonymous ID assigned to the user before the identify event was called
36
+ */
37
+ this.getAnonymousId = function () { return RudderAnalytics.getAnonymousId(); };
38
+ /**
39
+ * @returns The user ID that was assigned to the user after calling identify event
40
+ */
41
+ this.getUserId = function () { return RudderAnalytics.getUserId(); };
42
+ /**
43
+ * Initializes the Rudderstack SDK. Ensure that the appropriate environment variables are set before this is called.
44
+ * For local/staging environment, ensure that `RUDDERSTACK_STAGING_KEY` and `RUDDERSTACK_URL` is set.
45
+ * For production environment, ensure that `RUDDERSTACK_PRODUCTION_KEY` and `RUDDERSTACK_URL` is set.
46
+ */
47
+ this.init = function (RUDDERSTACK_KEY) {
48
+ if (RUDDERSTACK_KEY) {
49
+ RudderAnalytics.load(RUDDERSTACK_KEY, 'https://deriv-dataplane.rudderstack.com');
50
+ RudderAnalytics.ready(function () {
51
+ _this.has_initialized = true;
52
+ _this.has_identified = !!(_this.getUserId() || !!_this.getAnonymousId());
53
+ });
54
+ }
55
+ };
34
56
  /**
35
57
  *
36
58
  * @param user_id The user ID of the user to identify and associate all events with that particular user ID
@@ -40,6 +62,48 @@ var RudderStack = /** @class */ (function () {
40
62
  RudderAnalytics.identify(user_id, payload);
41
63
  _this.has_identified = true;
42
64
  };
65
+ /**
66
+ * Pushes page view event to Rudderstack
67
+ *
68
+ * @param curret_page The name or URL of the current page to track the page view event
69
+ */
70
+ this.pageView = function (current_page, platform, user_id) {
71
+ if (platform === void 0) { platform = 'Deriv App'; }
72
+ if (_this.has_initialized && _this.has_identified && current_page !== _this.current_page) {
73
+ RudderAnalytics.page(platform, current_page, { user_id: user_id });
74
+ _this.current_page = current_page;
75
+ }
76
+ };
77
+ /**
78
+ * Pushes reset event to rudderstack
79
+ */
80
+ this.reset = function () {
81
+ if (_this.has_initialized) {
82
+ RudderAnalytics.reset();
83
+ _this.has_identified = false;
84
+ }
85
+ };
86
+ /**
87
+ * 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.
88
+ * Otherwise, if the events needs to be associated with a user ID, call `identifyEvent` with the user ID passed first before calling this method.
89
+ *
90
+ * @param event The event name to track
91
+ * @param payload Additional information related to the event
92
+ */
93
+ this.track = function (event, payload) {
94
+ var clean_payload = Object.fromEntries(Object.entries(payload).filter(function (_a) {
95
+ var _ = _a[0], value = _a[1];
96
+ return value !== undefined;
97
+ }));
98
+ if (_this.has_initialized && _this.has_identified) {
99
+ try {
100
+ RudderAnalytics.track(event, clean_payload);
101
+ }
102
+ catch (err) {
103
+ console.error(err);
104
+ }
105
+ }
106
+ };
43
107
  this.init(RUDDERSTACK_KEY);
44
108
  }
45
109
  RudderStack.getRudderStackInstance = function (RUDDERSTACK_KEY) {
@@ -49,71 +113,6 @@ var RudderStack = /** @class */ (function () {
49
113
  }
50
114
  return RudderStack._instance;
51
115
  };
52
- /**
53
- * @returns The anonymous ID assigned to the user before the identify event was called
54
- */
55
- RudderStack.prototype.getAnonymousId = function () {
56
- return RudderAnalytics.getAnonymousId();
57
- };
58
- /**
59
- * @returns The user ID that was assigned to the user after calling identify event
60
- */
61
- RudderStack.prototype.getUserId = function () {
62
- return RudderAnalytics.getUserId();
63
- };
64
- /**
65
- * Initializes the Rudderstack SDK. Ensure that the appropriate environment variables are set before this is called.
66
- * For local/staging environment, ensure that `RUDDERSTACK_STAGING_KEY` and `RUDDERSTACK_URL` is set.
67
- * For production environment, ensure that `RUDDERSTACK_PRODUCTION_KEY` and `RUDDERSTACK_URL` is set.
68
- */
69
- RudderStack.prototype.init = function (RUDDERSTACK_KEY) {
70
- var _this = this;
71
- if (RUDDERSTACK_KEY) {
72
- RudderAnalytics.load(RUDDERSTACK_KEY, 'https://deriv-dataplane.rudderstack.com');
73
- RudderAnalytics.ready(function () {
74
- _this.has_initialized = true;
75
- _this.has_identified = !!(_this.getUserId() || !!_this.getAnonymousId());
76
- });
77
- }
78
- };
79
- /**
80
- * Pushes page view event to Rudderstack
81
- *
82
- * @param curret_page The name or URL of the current page to track the page view event
83
- */
84
- RudderStack.prototype.pageView = function (current_page, platform, user_id) {
85
- if (platform === void 0) { platform = 'Deriv App'; }
86
- if (this.has_initialized && this.has_identified && current_page !== this.current_page) {
87
- RudderAnalytics.page(platform, current_page, { user_id: user_id });
88
- this.current_page = current_page;
89
- }
90
- };
91
- /**
92
- * Pushes reset event to rudderstack
93
- */
94
- RudderStack.prototype.reset = function () {
95
- if (this.has_initialized) {
96
- RudderAnalytics.reset();
97
- this.has_identified = false;
98
- }
99
- };
100
- /**
101
- * 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.
102
- * Otherwise, if the events needs to be associated with a user ID, call `identifyEvent` with the user ID passed first before calling this method.
103
- *
104
- * @param event The event name to track
105
- * @param payload Additional information related to the event
106
- */
107
- RudderStack.prototype.track = function (event, payload) {
108
- if (this.has_initialized && this.has_identified) {
109
- try {
110
- RudderAnalytics.track(event, payload);
111
- }
112
- catch (err) {
113
- console.error(err);
114
- }
115
- }
116
- };
117
116
  return RudderStack;
118
117
  }());
119
118
  exports.RudderStack = RudderStack;
package/lib/types.d.ts CHANGED
@@ -17,7 +17,7 @@ export type TCoreAttributes = {
17
17
  } & Partial<TGrowthbookAttributes>;
18
18
  type SignupProvider = 'email' | 'phone' | 'google' | 'facebook' | 'apple';
19
19
  type VirtualSignupForm = {
20
- action?: 'open' | 'started' | 'email_confirmation_sent' | 'email_confirmed' | 'signup_continued' | 'country_selection_screen_opened' | 'password_screen_opened' | 'signup_done' | 'signup_flow_error' | 'go_to_login';
20
+ action?: 'open' | 'started' | 'email_confirmation_sent' | 'email_confirmed' | 'signup_continued' | 'country_selection_screen_opened' | 'password_screen_opened' | 'signup_done' | 'signup_flow_error' | 'go_to_login' | 'signup_modal_open' | 'signup_modal_close';
21
21
  signup_provider?: SignupProvider;
22
22
  form_source?: string;
23
23
  form_name?: string;
@@ -65,13 +65,38 @@ type QuestionnaireForm = {
65
65
  answer_code?: string;
66
66
  };
67
67
  type PartnerAccountSignupForm = {
68
- action: 'open' | 'open_wizard' | 'step_passed' | 'step_back' | 'push_learn_more' | 'close_wizard' | 'close' | 'partners_signup_error' | 'other_error' | 'try_submit' | 'failed_popup_cta' | 'success_popup_opened' | 'success_popup_cta';
69
- step_codename?: string;
70
- step_num?: number;
71
- user_choice?: string;
72
- form_source?: string;
73
- form_name?: 'ce_partner_account_signup_form';
68
+ action: 'open_wizard';
69
+ email: string;
70
+ } | {
71
+ action: 'step_passed';
72
+ step_num: number;
73
+ step_codename: string;
74
+ } | {
75
+ action: 'step_back';
76
+ step_num: number;
77
+ step_codename: string;
78
+ } | {
79
+ action: 'push_learn_more';
80
+ } | {
81
+ action: 'close_wizard';
82
+ } | {
83
+ action: 'partners_signup_error';
84
+ partner_signup_error_message: string;
85
+ form_name?: string;
86
+ } | {
87
+ action: 'other_error';
74
88
  partner_signup_error_message?: string;
89
+ } | {
90
+ action: 'try_submit';
91
+ } | {
92
+ action: 'failed_popup_cta';
93
+ } | {
94
+ action: 'success_popup_opened';
95
+ user_choice: string;
96
+ success_source: string;
97
+ affiliate_id: string;
98
+ } | {
99
+ action: 'success_popup_cta';
75
100
  };
76
101
  type VirtualSignupEmailConfirmation = {
77
102
  action?: 'received' | 'expired' | 'confirmed' | 'error';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deriv-com/analytics",
3
- "version": "1.4.12",
3
+ "version": "1.5.0-beta",
4
4
  "description": "The analytics package contains all the utility functions used for tracking user events and sending them to the respective platform such as Rudderstack.",
5
5
  "keywords": [
6
6
  "rudderstack",
@@ -36,7 +36,7 @@
36
36
  "typescript": "^4.9.5"
37
37
  },
38
38
  "dependencies": {
39
- "@growthbook/growthbook": "^0.29.0",
39
+ "@growthbook/growthbook": "^0.36.0",
40
40
  "rudder-sdk-js": "^2.35.0"
41
41
  },
42
42
  "engines": {