@deriv-com/analytics 1.5.0-beta → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -29,6 +29,20 @@ Analytics?.initialise({
29
29
  growthbookDecryptionKey: process.env.GROWTHBOOK_DECRYPTION_KEY, // optional key to enable A/B tests
30
30
  // mandatory key to enable userevent tracking
31
31
  rudderstackKey: RUDDERSTACK_KEY,
32
+
33
+ growthbookOptions: {
34
+ // optional options for overriding growthbook default options
35
+ // if you want e.g
36
+ antiFlicker: false,
37
+ navigateDelay: 0,
38
+ antiFlickerTimeout: 3500,
39
+ subscribeToChanges: true,
40
+ enableDevMode: window?.location.hostname.includes('localhost'),
41
+ trackingCallback: (experiment, result) => {
42
+ console.log('Tracking callback', experiment, result)
43
+ }
44
+ navigate: (url) => window.location.href = url,
45
+ }
32
46
  })
33
47
  ```
34
48
 
@@ -10,7 +10,7 @@ type Options = {
10
10
  };
11
11
  export declare function createAnalyticsInstance(options?: Options): {
12
12
  initialise: ({ growthbookKey, growthbookDecryptionKey, rudderstackKey, growthbookOptions }: Options) => void;
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;
13
+ setAttributes: ({ country, user_language, device_language, device_type, account_type, user_id, app_id, utm_source, utm_medium, utm_campaign, is_authorised, url, }: TCoreAttributes) => void;
14
14
  identifyEvent: () => void;
15
15
  getFeatureState: (id: string) => string | undefined;
16
16
  getFeatureValue: <K extends string | number, V extends GrowthbookConfigs[K]>(id: K, defaultValue: V) => import("@growthbook/growthbook").WidenPrimitives<V>;
@@ -27,7 +27,7 @@ export declare function createAnalyticsInstance(options?: Options): {
27
27
  };
28
28
  export declare const Analytics: {
29
29
  initialise: ({ growthbookKey, growthbookDecryptionKey, rudderstackKey, growthbookOptions }: Options) => void;
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;
30
+ setAttributes: ({ country, user_language, device_language, device_type, account_type, user_id, app_id, utm_source, utm_medium, utm_campaign, is_authorised, url, }: TCoreAttributes) => void;
31
31
  identifyEvent: () => void;
32
32
  getFeatureState: (id: string) => string | undefined;
33
33
  getFeatureValue: <K extends string | number, V extends GrowthbookConfigs[K]>(id: K, defaultValue: V) => import("@growthbook/growthbook").WidenPrimitives<V>;
package/lib/analytics.js CHANGED
@@ -30,7 +30,7 @@ function createAnalyticsInstance(options) {
30
30
  }
31
31
  };
32
32
  var setAttributes = function (_a) {
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;
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, url = _a.url;
34
34
  if (!_growthbook && !_rudderstack)
35
35
  return;
36
36
  var user_identity = user_id !== null && user_id !== void 0 ? user_id : getId();
@@ -46,9 +46,10 @@ function createAnalyticsInstance(options) {
46
46
  utm_medium: utm_medium,
47
47
  utm_campaign: utm_campaign,
48
48
  is_authorised: is_authorised,
49
+ url: url,
49
50
  });
50
51
  }
51
- core_data = __assign(__assign(__assign(__assign(__assign({}, (user_language !== undefined && { user_language: user_language })), (account_type !== undefined && { account_type: account_type })), (app_id !== undefined && { app_id: app_id })), (device_type !== undefined && { device_type: device_type })), (user_identity !== undefined && { user_identity: user_identity }));
52
+ core_data = __assign(__assign(__assign(__assign(__assign(__assign({}, (user_language !== undefined && { user_language: user_language })), (account_type !== undefined && { account_type: account_type })), (app_id !== undefined && { app_id: app_id })), (device_type !== undefined && { device_type: device_type })), (user_identity !== undefined && { user_identity: user_identity })), (url !== undefined && { url: url }));
52
53
  };
53
54
  var getFeatureState = function (id) { var _a, _b; return (_b = (_a = _growthbook === null || _growthbook === void 0 ? void 0 : _growthbook.getFeatureState(id)) === null || _a === void 0 ? void 0 : _a.experimentResult) === null || _b === void 0 ? void 0 : _b.name; };
54
55
  var getFeatureValue = function (id, defaultValue) { return _growthbook === null || _growthbook === void 0 ? void 0 : _growthbook.getFeatureValue(id, defaultValue); };
@@ -10,7 +10,7 @@ export declare class Growthbook {
10
10
  private static _instance;
11
11
  constructor(clientKey: string, decryptionKey: string, settings?: Partial<Context>);
12
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;
13
+ setAttributes: ({ id, country, user_language, device_language, device_type, utm_source, utm_medium, utm_campaign, is_authorised, url, }: TGrowthbookAttributes) => void;
14
14
  getFeatureValue: <K extends string | number, V extends GrowthbookConfigs[K]>(key: K, defaultValue: V) => import("@growthbook/growthbook").WidenPrimitives<V>;
15
15
  getFeatureState: (id: string) => import("@growthbook/growthbook").FeatureResult<string | boolean | Record<string, boolean> | [] | null>;
16
16
  setUrl: (href: string) => Promise<void>;
package/lib/growthbook.js CHANGED
@@ -43,8 +43,8 @@ var Growthbook = /** @class */ (function () {
43
43
  if (settings === void 0) { settings = {}; }
44
44
  var _this = this;
45
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 })));
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, url = _a.url;
47
+ _this.GrowthBook.setAttributes(__assign(__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 })), (url !== undefined && { url: url })));
48
48
  };
49
49
  this.getFeatureValue = function (key, defaultValue) {
50
50
  return _this.GrowthBook.getFeatureValue(key, defaultValue);
@@ -53,7 +53,7 @@ var Growthbook = /** @class */ (function () {
53
53
  this.setUrl = function (href) { return _this.GrowthBook.setURL(href); };
54
54
  this.isOn = function (key) { return _this.GrowthBook.isOn(key); };
55
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) {
56
+ this.GrowthBook = new growthbook_1.GrowthBook(__assign({ apiHost: 'https://cdn.growthbook.io', clientKey: clientKey, decryptionKey: decryptionKey, antiFlicker: false, navigateDelay: 0, antiFlickerTimeout: 3500, subscribeToChanges: true, enableDevMode: window === null || window === void 0 ? void 0 : window.location.hostname.includes('localhost'), trackingCallback: function (experiment, result) {
57
57
  if (window.dataLayer) {
58
58
  window.dataLayer.push({
59
59
  event: 'experiment_viewed',
package/lib/types.d.ts CHANGED
@@ -8,6 +8,7 @@ export type TGrowthbookAttributes = {
8
8
  utm_medium?: 'ppc-native' | 'affiliate' | 'common' | string;
9
9
  utm_campaign?: string;
10
10
  is_authorised?: boolean;
11
+ url?: string;
11
12
  };
12
13
  export type TCoreAttributes = {
13
14
  account_type?: string;
@@ -245,6 +246,12 @@ type TradersHubOnboardingFormAction = {
245
246
  type UpgradeMT5BannerAction = {
246
247
  action: 'open' | 'push_cta_upgrade';
247
248
  };
249
+ type TradersHubDashboardFormAction = {
250
+ action?: 'open' | 'close' | 'switch_account_mode' | 'account_open' | 'account_get' | 'account_logo_push' | 'reset_balance' | 'deposit_balance' | 'compare_accounts_push';
251
+ form_source?: 'deriv_apps_dashboard' | 'tradershub_onboarding_form' | 'deriv_trader' | 'dtrader_account_form';
252
+ account_mode?: 'demo' | 'real';
253
+ account_name?: string;
254
+ };
248
255
  export type TEvents = {
249
256
  ce_virtual_signup_form: VirtualSignupForm;
250
257
  ce_email_verification_form: EmailVerificationForm;
@@ -267,5 +274,6 @@ export type TEvents = {
267
274
  ce_reports_form: ReportsFormAction;
268
275
  ce_tradershub_onboarding_form: TradersHubOnboardingFormAction;
269
276
  ce_upgrade_mt5_banner: UpgradeMT5BannerAction;
277
+ ce_tradershub_dashboard_form: TradersHubDashboardFormAction;
270
278
  };
271
279
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deriv-com/analytics",
3
- "version": "1.5.0-beta",
3
+ "version": "1.5.1",
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",