Skip to content

Commit

Permalink
Ako/fix analytics break on local (deriv-com#11033)
Browse files Browse the repository at this point in the history
* build: use version 1.3.7 of analytics package

* fix: to initialize the analytics on staging and production

* feat: init analytics on test links too

* fix: null check before calling
  • Loading branch information
ali-hosseini-deriv authored Oct 30, 2023
1 parent 37dea7c commit e54ca0e
Show file tree
Hide file tree
Showing 8 changed files with 25,475 additions and 68,861 deletions.
94,293 changes: 25,451 additions & 68,842 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 @@ -92,7 +92,7 @@
},
"dependencies": {
"@babel/preset-typescript": "^7.16.5",
"@deriv/analytics": "^1.3.4",
"@deriv/analytics": "^1.3.7",
"@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/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"@babel/polyfill": "^7.4.4",
"@datadog/browser-rum": "^4.37.0",
"@deriv/account": "^1.0.0",
"@deriv/analytics": "^1.3.4",
"@deriv/analytics": "^1.3.7",
"@deriv/api": "^1.0.0",
"@deriv/appstore": "^0.0.4",
"@deriv/wallets": "^1.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/App/Containers/Layout/app-contents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ const AppContents = observer(({ children }) => {

React.useEffect(() => {
if (is_logged_in && user_id) {
const { tracking } = Analytics.getInstances();
Analytics.setAttributes({
const { tracking } = Analytics?.getInstances();
Analytics?.setAttributes({
account_type: loginid.substring(0, 2),
});
tracking.identifyEvent(user_id, {
language: getLanguage().toLowerCase() || 'en',
});
Analytics.pageView(current_page);
Analytics?.pageView(current_page);
}
if (scroll_ref.current) setAppContentsScrollRef(scroll_ref);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Analytics.pageView(current_page);
Analytics?.pageView(current_page);

React.useEffect(() => {
const allow_tracking = !is_eu_country || tracking_status === 'accepted';
Expand Down
25 changes: 15 additions & 10 deletions packages/core/src/App/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,21 @@ const AppWithoutTranslation = ({ root_store }) => {
};

initializeTranslations();

Analytics.initialise({
growthbookKey: process.env.GROWTHBOOK_CLIENT_KEY,
growthbookDecryptionKey: process.env.GROWTHBOOK_DECRYPTION_KEY,
rudderstackKey:
process.env.NODE_ENV === 'production'
? process.env.RUDDERSTACK_PRODUCTION_KEY
: process.env.RUDDERSTACK_STAGING_KEY,
enableDevMode: process.env.NODE_ENV !== 'production',
});
if (
process.env.NODE_ENV === 'production' ||
process.env.NODE_ENV === 'staging' ||
process.env.NODE_ENV === 'test'
) {
Analytics.initialise({
growthbookKey: process.env.GROWTHBOOK_CLIENT_KEY,
growthbookDecryptionKey: process.env.GROWTHBOOK_DECRYPTION_KEY,
rudderstackKey:
process.env.NODE_ENV === 'production'
? process.env.RUDDERSTACK_PRODUCTION_KEY
: process.env.RUDDERSTACK_STAGING_KEY,
enableDevMode: process.env.NODE_ENV !== 'production',
});
}

// TODO: [translation-to-shared]: add translation implemnentation in shared
setUrlLanguage(getLanguage());
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,7 @@ export default class ClientStore extends BaseStore {
language: getLanguage().toLowerCase(),
});
const current_page = window.location.hostname + window.location.pathname;
Analytics.pageView(current_page);
Analytics?.pageView(current_page);

await this.root_store.gtm.pushDataLayer({
event: 'login',
Expand Down
2 changes: 1 addition & 1 deletion packages/reports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"webpack-node-externals": "^2.5.2"
},
"dependencies": {
"@deriv/analytics": "^1.3.4",
"@deriv/analytics": "^1.3.7",
"@deriv/components": "^1.0.0",
"@deriv/deriv-api": "^1.0.13",
"@deriv/shared": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/trader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"webpack-node-externals": "^2.5.2"
},
"dependencies": {
"@deriv/analytics": "^1.3.4",
"@deriv/analytics": "^1.3.7",
"@deriv/components": "^1.0.0",
"@deriv/deriv-api": "^1.0.13",
"@deriv/api-types": "^1.0.118",
Expand Down

0 comments on commit e54ca0e

Please sign in to comment.