@deriv-com/analytics 1.4.11 → 1.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/analytics.d.ts +5 -25
- package/lib/analytics.js +11 -12
- package/lib/growthbook.d.ts +13 -28
- package/lib/growthbook.js +12 -22
- package/lib/rudderstack.d.ts +8 -8
- package/lib/rudderstack.js +64 -65
- package/lib/types.d.ts +47 -6
- package/package.json +1 -1
package/lib/analytics.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Growthbook } from './growthbook';
|
1
|
+
import { Growthbook, GrowthbookConfigs } from './growthbook';
|
2
2
|
import { RudderStack } from './rudderstack';
|
3
3
|
import { TCoreAttributes, TEvents } from './types';
|
4
4
|
type Options = {
|
@@ -11,21 +11,11 @@ export declare function createAnalyticsInstance(options?: Options): {
|
|
11
11
|
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
12
|
identifyEvent: () => void;
|
13
13
|
getFeatureState: (id: string) => string | undefined;
|
14
|
-
getFeatureValue: <
|
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);
|
14
|
+
getFeatureValue: <K extends string | number, V extends GrowthbookConfigs[K]>(id: K, defaultValue: V) => import("@growthbook/growthbook").WidenPrimitives<V>;
|
25
15
|
isFeatureOn: (key: string) => boolean;
|
26
16
|
setUrl: (href: string) => void;
|
27
17
|
getId: () => string;
|
28
|
-
trackEvent: <
|
18
|
+
trackEvent: <T extends keyof TEvents>(event: T, analytics_data: TEvents[T]) => void;
|
29
19
|
getInstances: () => {
|
30
20
|
ab: Growthbook;
|
31
21
|
tracking: RudderStack;
|
@@ -38,21 +28,11 @@ export declare const Analytics: {
|
|
38
28
|
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
29
|
identifyEvent: () => void;
|
40
30
|
getFeatureState: (id: string) => string | undefined;
|
41
|
-
getFeatureValue: <
|
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);
|
31
|
+
getFeatureValue: <K extends string | number, V extends GrowthbookConfigs[K]>(id: K, defaultValue: V) => import("@growthbook/growthbook").WidenPrimitives<V>;
|
52
32
|
isFeatureOn: (key: string) => boolean;
|
53
33
|
setUrl: (href: string) => void;
|
54
34
|
getId: () => string;
|
55
|
-
trackEvent: <
|
35
|
+
trackEvent: <T extends keyof TEvents>(event: T, analytics_data: TEvents[T]) => void;
|
56
36
|
getInstances: () => {
|
57
37
|
ab: Growthbook;
|
58
38
|
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 = {},
|
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
20
|
var growthbookKey = _a.growthbookKey, growthbookDecryptionKey = _a.growthbookDecryptionKey, rudderstackKey = _a.rudderstackKey;
|
27
21
|
_rudderstack = rudderstack_1.RudderStack.getRudderStackInstance(rudderstackKey);
|
28
22
|
if (growthbookKey && growthbookDecryptionKey) {
|
29
23
|
_growthbook = growthbook_1.Growthbook.getGrowthBookInstance(growthbookKey, growthbookDecryptionKey);
|
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).
|
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
|
90
|
-
|
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));
|
package/lib/growthbook.d.ts
CHANGED
@@ -1,34 +1,19 @@
|
|
1
1
|
import { 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<
|
9
|
+
GrowthBook: GrowthBook<GrowthbookConfigs>;
|
5
10
|
private static _instance;
|
6
11
|
constructor(clientKey: string, decryptionKey: string);
|
7
|
-
static getGrowthBookInstance(clientKey: string, decryptionKey: string)
|
8
|
-
setAttributes({ id, country, user_language, device_language, device_type, utm_source, utm_medium, utm_campaign, is_authorised, }: TGrowthbookAttributes)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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;
|
12
|
+
static getGrowthBookInstance: (clientKey: string, decryptionKey: string) => 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) => void;
|
17
|
+
isOn: (key: string) => boolean;
|
18
|
+
init: () => Promise<void>;
|
34
19
|
}
|
package/lib/growthbook.js
CHANGED
@@ -40,6 +40,18 @@ 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
42
|
function Growthbook(clientKey, decryptionKey) {
|
43
|
+
var _this = this;
|
44
|
+
this.setAttributes = function (_a) {
|
45
|
+
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;
|
46
|
+
_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 })));
|
47
|
+
};
|
48
|
+
this.getFeatureValue = function (key, defaultValue) {
|
49
|
+
return _this.GrowthBook.getFeatureValue(key, defaultValue);
|
50
|
+
};
|
51
|
+
this.getFeatureState = function (id) { return _this.GrowthBook.evalFeature(id); };
|
52
|
+
this.setUrl = function (href) { return _this.GrowthBook.setURL(href); };
|
53
|
+
this.isOn = function (key) { return _this.GrowthBook.isOn(key); };
|
54
|
+
this.init = function () { return _this.GrowthBook.loadFeatures().catch(function (err) { return console.error(err); }); };
|
43
55
|
this.GrowthBook = new growthbook_1.GrowthBook({
|
44
56
|
apiHost: 'https://cdn.growthbook.io',
|
45
57
|
clientKey: clientKey,
|
@@ -72,28 +84,6 @@ var Growthbook = /** @class */ (function () {
|
|
72
84
|
}
|
73
85
|
return Growthbook._instance;
|
74
86
|
};
|
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
87
|
return Growthbook;
|
98
88
|
}());
|
99
89
|
exports.Growthbook = Growthbook;
|
package/lib/rudderstack.d.ts
CHANGED
@@ -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)
|
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()
|
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()
|
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)
|
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)
|
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()
|
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])
|
48
|
+
track: <T extends keyof TEvents>(event: T, payload: TEvents[T] & Partial<TCoreAttributes>) => void;
|
49
49
|
}
|
package/lib/rudderstack.js
CHANGED
@@ -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
@@ -65,13 +65,38 @@ type QuestionnaireForm = {
|
|
65
65
|
answer_code?: string;
|
66
66
|
};
|
67
67
|
type PartnerAccountSignupForm = {
|
68
|
-
action: '
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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';
|
@@ -196,6 +221,21 @@ type ChartTypesFormAction = {
|
|
196
221
|
chart_type_name?: string;
|
197
222
|
time_interval_name?: string;
|
198
223
|
};
|
224
|
+
type ContractsSetupForm = {
|
225
|
+
form_name: string;
|
226
|
+
trade_type_name: string;
|
227
|
+
} & ({
|
228
|
+
action: 'change_parameter_value';
|
229
|
+
duration_type?: string;
|
230
|
+
input_type?: string;
|
231
|
+
parameter_field_type?: string;
|
232
|
+
parameter_type?: string;
|
233
|
+
parameter_value?: string;
|
234
|
+
} | {
|
235
|
+
action: 'run_contract';
|
236
|
+
switcher_duration_mode_name?: string;
|
237
|
+
switcher_stakepayout_mode_name?: string;
|
238
|
+
});
|
199
239
|
type TradersHubOnboardingFormAction = {
|
200
240
|
action?: 'open' | 'close' | 'step_passed' | 'step_back' | 'choose_step_navigation';
|
201
241
|
form_source?: 'tradershub_dashboard_form' | 'tradershub_first_entrance' | 'repeat_tour';
|
@@ -219,6 +259,7 @@ export type TEvents = {
|
|
219
259
|
ce_bot_quick_strategy_form: BotQuickStrategyForm;
|
220
260
|
ce_bot_builder_form: BotBuilderForm;
|
221
261
|
ce_bot_tutorial_form: BotTutorialForm;
|
262
|
+
ce_contracts_set_up_form: ContractsSetupForm;
|
222
263
|
ce_indicators_types_form: IndicatorsTypesFormAction;
|
223
264
|
ce_trade_types_form: TradeTypesForm;
|
224
265
|
ce_chart_types_form: ChartTypesFormAction;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@deriv-com/analytics",
|
3
|
-
"version": "1.4.
|
3
|
+
"version": "1.4.13",
|
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",
|