Skip to content

Commit 21f0a3f

Browse files
Aswathy/fix: testing the loggedin status (#18041)
* fix: testing the loggedin status * chore: empty commit * fix: upgraded the analytics version * fix: logged out loading issue
1 parent c31f2e8 commit 21f0a3f

File tree

2 files changed

+59
-39
lines changed

2 files changed

+59
-39
lines changed

packages/core/src/Stores/client-store.js

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,26 @@ export default class ClientStore extends BaseStore {
18221822
const is_virtual = account.is_virtual;
18231823
const account_type = !is_virtual && currency ? currency : this.account_title;
18241824

1825+
setTimeout(async () => {
1826+
const analytics_config = await this.getAnalyticsConfig();
1827+
if (this.user_id) analytics_config.user_id = this.user_id;
1828+
Analytics.setAttributes(analytics_config);
1829+
}, 4);
1830+
1831+
return {
1832+
loginid,
1833+
is_disabled,
1834+
is_virtual,
1835+
icon: account_type.toLowerCase(), // TODO: display the icon
1836+
title: account_type.toLowerCase() === 'virtual' ? localize('DEMO') : account_type,
1837+
};
1838+
}
1839+
1840+
async getAnalyticsConfig(isLoggedOut = false) {
1841+
const broker = LocalStore?.get('active_loginid')
1842+
?.match(/[a-zA-Z]+/g)
1843+
?.join('');
1844+
18251845
const ppc_campaign_cookies =
18261846
Cookies.getJSON('utm_data') === 'null'
18271847
? {
@@ -1831,11 +1851,9 @@ export default class ClientStore extends BaseStore {
18311851
utm_content: 'no content',
18321852
}
18331853
: Cookies.getJSON('utm_data');
1834-
const broker = LocalStore?.get('active_loginid')
1835-
?.match(/[a-zA-Z]+/g)
1836-
?.join('');
1837-
setTimeout(async () => {
1838-
let residence_country = '';
1854+
1855+
let residence_country = '';
1856+
if (!isLoggedOut) {
18391857
if (this.residence) {
18401858
residence_country = this.residence;
18411859
} else {
@@ -1849,35 +1867,28 @@ export default class ClientStore extends BaseStore {
18491867
console.error('Error getting residence country', error);
18501868
}
18511869
}
1852-
1853-
const analytics_config = {
1854-
loggedIn: this.is_logged_in,
1855-
account_type: broker === 'null' ? 'unlogged' : broker,
1856-
residence_country,
1857-
app_id: String(getAppId()),
1858-
device_type: isMobile() ? 'mobile' : 'desktop',
1859-
language: getLanguage(),
1860-
device_language: navigator?.language || 'en-EN',
1861-
user_language: getLanguage().toLowerCase(),
1862-
country: await CountryUtils.getCountry(),
1863-
utm_source: ppc_campaign_cookies?.utm_source,
1864-
utm_medium: ppc_campaign_cookies?.utm_medium,
1865-
utm_campaign: ppc_campaign_cookies?.utm_campaign,
1866-
utm_content: ppc_campaign_cookies?.utm_content,
1867-
domain: window.location.hostname,
1868-
url: window.location.href,
1869-
};
1870-
1871-
if (this.user_id) analytics_config.user_id = this.user_id;
1872-
Analytics.setAttributes(analytics_config);
1873-
}, 4);
1870+
}
1871+
let login_status = false;
1872+
if (!isLoggedOut && this.is_logged_in) {
1873+
login_status = true;
1874+
}
18741875

18751876
return {
1876-
loginid,
1877-
is_disabled,
1878-
is_virtual,
1879-
icon: account_type.toLowerCase(), // TODO: display the icon
1880-
title: account_type.toLowerCase() === 'virtual' ? localize('DEMO') : account_type,
1877+
loggedIn: login_status,
1878+
account_type: broker === 'null' ? 'unlogged' : broker,
1879+
residence_country,
1880+
app_id: String(getAppId()),
1881+
device_type: isMobile() ? 'mobile' : 'desktop',
1882+
language: getLanguage(),
1883+
device_language: navigator?.language || 'en-EN',
1884+
user_language: getLanguage().toLowerCase(),
1885+
country: await CountryUtils.getCountry(),
1886+
utm_source: ppc_campaign_cookies?.utm_source,
1887+
utm_medium: ppc_campaign_cookies?.utm_medium,
1888+
utm_campaign: ppc_campaign_cookies?.utm_campaign,
1889+
utm_content: ppc_campaign_cookies?.utm_content,
1890+
domain: window.location.hostname,
1891+
url: window.location.href,
18811892
};
18821893
}
18831894

@@ -1914,7 +1925,7 @@ export default class ClientStore extends BaseStore {
19141925
}
19151926

19161927
async switchAccountHandler() {
1917-
if (!this.switched || !this.switched.length || !this.getAccount(this.switched)?.token) {
1928+
if (!this.switched || !this.switched.length) {
19181929
if (this.isUnableToFindLoginId()) {
19191930
this.handleNotFoundLoginId();
19201931
return;
@@ -1932,6 +1943,12 @@ export default class ClientStore extends BaseStore {
19321943
return;
19331944
}
19341945

1946+
const switched_account = this.getAccount(this.switched);
1947+
if (!switched_account?.token) {
1948+
this.handleNotFoundLoginId();
1949+
return;
1950+
}
1951+
19351952
runInAction(() => (this.is_switching = true));
19361953
this.setIsAuthorize(false);
19371954
const from_login_id = this.loginid;
@@ -1948,7 +1965,7 @@ export default class ClientStore extends BaseStore {
19481965
await BinarySocket?.wait('authorize');
19491966
} else {
19501967
await WS.forgetAll('balance');
1951-
await BinarySocket.authorize(this.getToken());
1968+
await BinarySocket.authorize(switched_account.token);
19521969
}
19531970
if (this.root_store.common.has_error) this.root_store.common.setError(false, null);
19541971
sessionStorage.setItem('active_tab', '1');
@@ -2093,7 +2110,7 @@ export default class ClientStore extends BaseStore {
20932110
this.initialized_broadcast = is_initialized;
20942111
}
20952112

2096-
cleanUp() {
2113+
async cleanUp() {
20972114
// delete all notifications keys for this account when logout
20982115
const notification_messages = LocalStore.getObject('notification_messages');
20992116
if (notification_messages && this.loginid) {
@@ -2102,6 +2119,9 @@ export default class ClientStore extends BaseStore {
21022119
...notification_messages,
21032120
});
21042121
}
2122+
// update growthbook
2123+
const analytics_config = await this.getAnalyticsConfig(true);
2124+
Analytics.setAttributes(analytics_config);
21052125

21062126
this.root_store.gtm.pushDataLayer({
21072127
event: 'log_out',
@@ -2135,7 +2155,7 @@ export default class ClientStore extends BaseStore {
21352155
const response = await requestLogout();
21362156

21372157
if (response?.logout === 1) {
2138-
this.cleanUp();
2158+
await this.cleanUp();
21392159

21402160
this.setLogout(true);
21412161
}

packages/core/src/Utils/Analytics/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ export const AnalyticsInitializer = async () => {
1818
.catch(() => FIREBASE_INIT_DATA);
1919
if (process.env.RUDDERSTACK_KEY && flags?.tracking_rudderstack) {
2020
const ppc_campaign_cookies =
21-
Cookies.getJSON('utm_data') === 'null'
21+
JSON.parse(Cookies.get('utm_data') || 'null') === 'null'
2222
? {
2323
utm_source: 'no source',
2424
utm_medium: 'no medium',
2525
utm_campaign: 'no campaign',
2626
utm_content: 'no content',
2727
}
28-
: Cookies.getJSON('utm_data');
28+
: JSON.parse(Cookies.get('utm_data') || 'null');
2929

30-
const client_information = Cookies.getJSON('client_information');
30+
const client_information = JSON.parse(Cookies.get('client_information') || 'null');
3131

3232
const config = {
3333
growthbookKey: flags.marketing_growthbook ? process.env.GROWTHBOOK_CLIENT_KEY : undefined,

0 commit comments

Comments
 (0)