Skip to content

Commit

Permalink
Ako/ CRO-724/ Pass growthbook attributes on initialisation (#16713)
Browse files Browse the repository at this point in the history
* build: update analytics to ver 1.13.0

* build: update to version 1.14

* feat: add user_id only if its available

* test: fix analytics test cases

* feat: pass the attributes on GB initialisation

* build: match the js-cookie types with the package version

* fix: remove country property as its built in to the analytics package

* build: update to 1.15.0 to also include changes for the new location implementation

* chore: revert the icons file changes

* Revert "build: update to 1.15.0 to also include changes for the new location implementation"

This reverts commit 67445cb.

* Revert "fix: remove country property as its built in to the analytics package"

This reverts commit e8dcc9e.

* chore: change import statement
  • Loading branch information
ali-hosseini-deriv committed Sep 6, 2024
1 parent 31b3dcf commit d3b3292
Show file tree
Hide file tree
Showing 18 changed files with 362 additions and 524 deletions.
806 changes: 322 additions & 484 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
"dependencies": {
"@babel/preset-typescript": "^7.16.5",
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@sendbird/chat": "^4.9.7",
"@types/react-transition-group": "^4.4.4",
"babel-jest": "^27.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@binary-com/binary-document-uploader": "^2.4.8",
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@deriv-com/translations": "1.3.5",
"@deriv-com/utils": "^0.0.25",
"@deriv-com/ui": "1.29.10",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"uuid": "^9.0.1"
},
"devDependencies": {
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@deriv/api-types": "1.0.172",
"@testing-library/react": "^12.0.0",
"@testing-library/react-hooks": "^7.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/appstore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"author": "Deriv",
"license": "Apache-2.0",
"dependencies": {
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@deriv-com/translations": "1.3.5",
"@deriv-com/ui": "1.29.10",
"@deriv/account": "^1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jest.mock('@deriv/hooks', () => ({
}));

jest.mock('@deriv-com/analytics', () => ({
...jest.requireActual('@deriv-com/analytics'),
Analytics: {
trackEvent: jest.fn(),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jest.mock('@deriv-com/ui', () => ({
}));

jest.mock('@deriv-com/analytics', () => ({
...jest.requireActual('@deriv-com/analytics'),
Analytics: {
trackEvent: jest.fn(),
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cashier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"url": "https://github.com/binary-com/deriv-app/issues"
},
"dependencies": {
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@deriv-com/ui": "1.29.10",
"@deriv/api": "^1.0.0",
"@deriv/api-types": "1.0.172",
Expand Down
2 changes: 1 addition & 1 deletion packages/cfd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"webpack-node-externals": "^2.5.2"
},
"dependencies": {
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@deriv-com/ui": "1.29.10",
"@deriv-com/translations": "1.3.5",
"@deriv-com/utils": "^0.0.25",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"dependencies": {
"@babel/polyfill": "^7.4.4",
"@datadog/browser-rum": "^5.11.0",
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@deriv-com/quill-tokens": "^2.0.4",
"@deriv-com/quill-ui": "1.16.5",
"@deriv-com/translations": "1.3.5",
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1767,8 +1767,7 @@ export default class ClientStore extends BaseStore {
?.match(/[a-zA-Z]+/g)
?.join('');
setTimeout(() => {
Analytics.setAttributes({
user_id: this.user_id,
const analytics_config = {
account_type: broker === 'null' ? 'unlogged' : broker,
residence_country: this.residence,
app_id: String(getAppId()),
Expand All @@ -1782,7 +1781,9 @@ export default class ClientStore extends BaseStore {
utm_campaign: ppc_campaign_cookies?.utm_campaign,
utm_content: ppc_campaign_cookies?.utm_content,
domain: window.location.hostname,
});
};
if (this.user_id) analytics_config.user_id = this.user_id;
Analytics.setAttributes(analytics_config);
}, 4);

return {
Expand Down
43 changes: 22 additions & 21 deletions packages/core/src/Utils/Analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ export const AnalyticsInitializer = async () => {
.then(res => res.json())
.catch(() => FIREBASE_INIT_DATA);
if (process.env.RUDDERSTACK_KEY && flags?.tracking_rudderstack) {
const config = {
growthbookKey: flags.marketing_growthbook ? process.env.GROWTHBOOK_CLIENT_KEY : undefined,
growthbookDecryptionKey: flags.marketing_growthbook ? process.env.GROWTHBOOK_DECRYPTION_KEY : undefined,
rudderstackKey: process.env.RUDDERSTACK_KEY,
};
await Analytics?.initialise(config);
await Analytics?.getInstances()?.ab?.GrowthBook?.loadFeatures();
const ppc_campaign_cookies =
Cookies.getJSON('utm_data') === 'null'
? {
Expand All @@ -30,20 +23,28 @@ export const AnalyticsInitializer = async () => {
utm_content: 'no content',
}
: Cookies.getJSON('utm_data');

Analytics.setAttributes({
account_type: account_type === 'null' ? 'unlogged' : account_type,
app_id: String(getAppId()),
device_type: window.innerWidth <= MAX_MOBILE_WIDTH ? 'mobile' : 'desktop',
device_language: navigator?.language || 'en-EN',
user_language: getLanguage().toLowerCase(),
country: Cookies.get('clients_country') || Cookies?.getJSON('website_status')?.clients_country,
utm_source: ppc_campaign_cookies?.utm_source,
utm_medium: ppc_campaign_cookies?.utm_medium,
utm_campaign: ppc_campaign_cookies?.utm_campaign,
utm_content: ppc_campaign_cookies?.utm_content,
domain: window.location.hostname,
});
const config = {
growthbookKey: flags.marketing_growthbook ? process.env.GROWTHBOOK_CLIENT_KEY : undefined,
growthbookDecryptionKey: flags.marketing_growthbook ? process.env.GROWTHBOOK_DECRYPTION_KEY : undefined,
rudderstackKey: process.env.RUDDERSTACK_KEY,
growthbookOptions: {
attributes: {
account_type: account_type === 'null' ? 'unlogged' : account_type,
app_id: String(getAppId()),
device_type: window.innerWidth <= MAX_MOBILE_WIDTH ? 'mobile' : 'desktop',
device_language: navigator?.language || 'en-EN',
user_language: getLanguage().toLowerCase(),
country:
Cookies.getJSON('clients_country') || Cookies?.getJSON('website_status')?.clients_country,
utm_source: ppc_campaign_cookies?.utm_source,
utm_medium: ppc_campaign_cookies?.utm_medium,
utm_campaign: ppc_campaign_cookies?.utm_campaign,
utm_content: ppc_campaign_cookies?.utm_content,
domain: window.location.hostname,
},
},
};
await Analytics?.initialise(config);
}
}
};
2 changes: 1 addition & 1 deletion packages/hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"sideEffects": false,
"dependencies": {
"@binary-com/binary-document-uploader": "^2.4.8",
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@deriv/api": "^1.0.0",
"@deriv/stores": "^1.0.0",
"@deriv/utils": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/p2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@deriv-com/ui": "1.29.10",
"@deriv-com/utils": "^0.0.25",
"@deriv/api": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/reports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"webpack-node-externals": "^2.5.2"
},
"dependencies": {
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@deriv-com/ui": "1.29.10",
"@deriv/components": "^1.0.0",
"@deriv/deriv-api": "^1.0.15",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
"typescript": "^4.6.3"
},
"dependencies": {
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@deriv/quill-icons": "1.23.3",
"@deriv/api-types": "1.0.172",
"@deriv/translations": "^1.0.0",
"@types/js-cookie": "^3.0.1",
"@types/js-cookie": "^2.2.1",
"@types/react-loadable": "^5.5.6",
"canvas-toBlob": "^1.0.0",
"extend": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/trader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"webpack-node-externals": "^2.5.2"
},
"dependencies": {
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@deriv-com/quill-tokens": "^2.0.4",
"@deriv-com/quill-ui": "1.16.5",
"@deriv-com/utils": "^0.0.25",
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"start": "rimraf dist && npm run test && npm run serve"
},
"dependencies": {
"@deriv-com/analytics": "1.12.1",
"@deriv-com/analytics": "1.14.0",
"@deriv-com/translations": "1.3.5",
"@deriv-com/ui": "1.29.10",
"@deriv-com/utils": "^0.0.25",
Expand Down

0 comments on commit d3b3292

Please sign in to comment.