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

Aswathy/fix: testing the loggedin status #18041

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
},
"dependencies": {
"@babel/preset-typescript": "^7.24.7",
"@deriv-com/analytics": "1.28.2",
"@deriv-com/analytics": "1.30.2",
"@sendbird/chat": "^4.9.7",
"@types/react-transition-group": "^4.4.4",
"babel-jest": "^29.7.0",
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.28.2",
"@deriv-com/analytics": "1.30.2",
"@deriv-com/translations": "1.3.9",
"@deriv-com/utils": "^0.0.42",
"@deriv-com/ui": "1.36.4",
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 @@ -16,7 +16,7 @@
"uuid": "^9.0.1"
},
"devDependencies": {
"@deriv-com/analytics": "1.28.2",
"@deriv-com/analytics": "1.30.2",
"@deriv/api-types": "1.0.172",
"@testing-library/react": "^12.1.5",
"@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.28.2",
"@deriv-com/analytics": "1.30.2",
"@deriv-com/translations": "1.3.9",
"@deriv-com/ui": "1.36.4",
"@deriv/account": "^1.0.0",
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/deriv-com/deriv-app/issues"
},
"dependencies": {
"@deriv-com/analytics": "1.28.2",
"@deriv-com/analytics": "1.30.2",
"@deriv-com/ui": "1.36.4",
"@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 @@ -86,7 +86,7 @@
},
"dependencies": {
"@deriv-com/ui": "1.36.4",
"@deriv-com/analytics": "1.28.2",
"@deriv-com/analytics": "1.30.2",
"@deriv-com/translations": "1.3.9",
"@deriv/quill-icons": "2.2.1",
"@deriv-com/utils": "^0.0.42",
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.12.1 ",
"@datadog/browser-rum": "^5.11.0",
"@deriv-com/analytics": "1.28.2",
"@deriv-com/analytics": "1.30.2",
"@deriv-com/auth-client": "^1.3.10",
"@deriv-com/quill-tokens": "2.0.4",
"@deriv-com/quill-ui": "1.24.4",
Expand Down
82 changes: 48 additions & 34 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,26 @@ export default class ClientStore extends BaseStore {
const is_virtual = account.is_virtual;
const account_type = !is_virtual && currency ? currency : this.account_title;

setTimeout(async () => {
const analytics_config = await this.getAnalyticsConfig();
if (this.user_id) analytics_config.user_id = this.user_id;
Analytics.setAttributes(analytics_config);
}, 4);

return {
loginid,
is_disabled,
is_virtual,
icon: account_type.toLowerCase(), // TODO: display the icon
title: account_type.toLowerCase() === 'virtual' ? localize('DEMO') : account_type,
};
}

async getAnalyticsConfig(isLoggedOut = false) {
const broker = LocalStore?.get('active_loginid')
?.match(/[a-zA-Z]+/g)
?.join('');

const ppc_campaign_cookies =
Cookies.getJSON('utm_data') === 'null'
? {
Expand All @@ -1831,11 +1851,9 @@ export default class ClientStore extends BaseStore {
utm_content: 'no content',
}
: Cookies.getJSON('utm_data');
const broker = LocalStore?.get('active_loginid')
?.match(/[a-zA-Z]+/g)
?.join('');
setTimeout(async () => {
let residence_country = '';

let residence_country = '';
if (!isLoggedOut) {
if (this.residence) {
residence_country = this.residence;
} else {
Expand All @@ -1849,35 +1867,28 @@ export default class ClientStore extends BaseStore {
console.error('Error getting residence country', error);
}
}

const analytics_config = {
loggedIn: this.is_logged_in,
account_type: broker === 'null' ? 'unlogged' : broker,
residence_country,
app_id: String(getAppId()),
device_type: isMobile() ? 'mobile' : 'desktop',
language: getLanguage(),
device_language: navigator?.language || 'en-EN',
user_language: getLanguage().toLowerCase(),
country: await CountryUtils.getCountry(),
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,
url: window.location.href,
};

if (this.user_id) analytics_config.user_id = this.user_id;
Analytics.setAttributes(analytics_config);
}, 4);
}
let login_status = false;
if (!isLoggedOut && this.is_logged_in) {
login_status = true;
}

return {
loginid,
is_disabled,
is_virtual,
icon: account_type.toLowerCase(), // TODO: display the icon
title: account_type.toLowerCase() === 'virtual' ? localize('DEMO') : account_type,
loggedIn: login_status,
account_type: broker === 'null' ? 'unlogged' : broker,
residence_country,
app_id: String(getAppId()),
device_type: isMobile() ? 'mobile' : 'desktop',
language: getLanguage(),
device_language: navigator?.language || 'en-EN',
user_language: getLanguage().toLowerCase(),
country: await CountryUtils.getCountry(),
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,
url: window.location.href,
};
}

Expand Down Expand Up @@ -2093,7 +2104,7 @@ export default class ClientStore extends BaseStore {
this.initialized_broadcast = is_initialized;
}

cleanUp() {
async cleanUp() {
// delete all notifications keys for this account when logout
const notification_messages = LocalStore.getObject('notification_messages');
if (notification_messages && this.loginid) {
Expand All @@ -2102,6 +2113,9 @@ export default class ClientStore extends BaseStore {
...notification_messages,
});
}
// update growthbook
const analytics_config = await this.getAnalyticsConfig(true);
Analytics.setAttributes(analytics_config);

this.root_store.gtm.pushDataLayer({
event: 'log_out',
Expand Down Expand Up @@ -2135,7 +2149,7 @@ export default class ClientStore extends BaseStore {
const response = await requestLogout();

if (response?.logout === 1) {
this.cleanUp();
await this.cleanUp();

this.setLogout(true);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/Utils/Analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ export const AnalyticsInitializer = async () => {
.catch(() => FIREBASE_INIT_DATA);
if (process.env.RUDDERSTACK_KEY && flags?.tracking_rudderstack) {
const ppc_campaign_cookies =
Cookies.getJSON('utm_data') === 'null'
JSON.parse(Cookies.get('utm_data') || 'null') === 'null'
? {
utm_source: 'no source',
utm_medium: 'no medium',
utm_campaign: 'no campaign',
utm_content: 'no content',
}
: Cookies.getJSON('utm_data');
: JSON.parse(Cookies.get('utm_data') || 'null');

const client_information = Cookies.getJSON('client_information');
const client_information = JSON.parse(Cookies.get('client_information') || 'null');

const config = {
growthbookKey: flags.marketing_growthbook ? process.env.GROWTHBOOK_CLIENT_KEY : undefined,
Expand Down
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.28.2",
"@deriv-com/analytics": "1.30.2",
"@deriv-com/auth-client": "^1.3.10",
"@deriv-com/ui": "1.36.4",
"@deriv-com/utils": "^0.0.42",
Expand Down
2 changes: 1 addition & 1 deletion packages/p2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"license": "ISC",
"dependencies": {
"@deriv-com/ui": "1.36.4",
"@deriv-com/analytics": "1.28.2",
"@deriv-com/analytics": "1.30.2",
"@deriv-com/utils": "^0.0.42",
"@deriv/api": "^1.0.0",
"@deriv/api-types": "1.0.172",
Expand Down
2 changes: 1 addition & 1 deletion packages/reports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
},
"dependencies": {
"@deriv-com/ui": "1.36.4",
"@deriv-com/analytics": "1.28.2",
"@deriv-com/analytics": "1.30.2",
"@deriv/components": "^1.0.0",
"@deriv/deriv-api": "^1.0.15",
"@deriv/api-types": "1.0.172",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"typescript": "^4.6.3"
},
"dependencies": {
"@deriv-com/analytics": "1.28.2",
"@deriv-com/analytics": "1.30.2",
"@deriv/quill-icons": "2.2.1",
"@deriv/api-types": "1.0.172",
"@deriv/translations": "^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 @@ -88,7 +88,7 @@
"webpack-node-externals": "^2.5.2"
},
"dependencies": {
"@deriv-com/analytics": "1.28.2",
"@deriv-com/analytics": "1.30.2",
"@deriv-com/quill-tokens": "2.0.4",
"@deriv-com/utils": "^0.0.42",
"@deriv-com/quill-ui": "1.24.4",
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.28.2",
"@deriv-com/analytics": "1.30.2",
"@deriv-com/translations": "1.3.9",
"@deriv-com/ui": "1.36.4",
"@deriv-com/utils": "^0.0.42",
Expand Down
Loading