Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ako/ CRO-724/ Pass growthbook attributes on initialisation #16713

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
821 changes: 334 additions & 487 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.15.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.15.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.15.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.15.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'),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

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.15.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.15.0",
"@deriv-com/ui": "1.29.10",
"@deriv-com/translations": "1.3.5",
"@deriv-com/utils": "^0.0.25",
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/components/icon/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,6 @@ import './option/ic-option-over-under.svg';
import './option/ic-option-raise-fall.svg';
import './option/ic-option-touch-notouch.svg';
import './option/ic-option-up-down-asian.svg';
import './rebranding/ic-rebranding-binary-bot.svg';
import './rebranding/ic-rebranding-ctrader-dashboard.svg';
import './rebranding/ic-rebranding-deriv-bot-dashboard.svg';
import './rebranding/ic-rebranding-deriv-bot.svg';
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.15.0",
"@deriv-com/quill-tokens": "^2.0.4",
"@deriv-com/quill-ui": "1.15.0",
"@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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure that we are not passing empty string to analytics package as it can override the current one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

country: Cookies.get('clients_country') || Cookies?.getJSON('website_status')?.clients_country,
This is called in the analytics right.we can remove it from here no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For that I need to bump up the analytics package again.
Because its in the newer version of the package.

Analytics.setAttributes(analytics_config);
}, 4);

return {
Expand Down
41 changes: 20 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,26 @@ 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: {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to pass the attributes in init config of Growthbook

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(),
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.15.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.15.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.15.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.15.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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match the types with the package it self

"@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.15.0",
"@deriv-com/quill-tokens": "^2.0.4",
"@deriv-com/quill-ui": "1.15.0",
"@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.15.0",
"@deriv-com/translations": "1.3.5",
"@deriv-com/ui": "1.29.10",
"@deriv-com/utils": "^0.0.25",
Expand Down
Loading