@@ -1822,6 +1822,26 @@ export default class ClientStore extends BaseStore {
1822
1822
const is_virtual = account . is_virtual ;
1823
1823
const account_type = ! is_virtual && currency ? currency : this . account_title ;
1824
1824
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 - z A - Z ] + / g)
1843
+ ?. join ( '' ) ;
1844
+
1825
1845
const ppc_campaign_cookies =
1826
1846
Cookies . getJSON ( 'utm_data' ) === 'null'
1827
1847
? {
@@ -1831,11 +1851,9 @@ export default class ClientStore extends BaseStore {
1831
1851
utm_content : 'no content' ,
1832
1852
}
1833
1853
: Cookies . getJSON ( 'utm_data' ) ;
1834
- const broker = LocalStore ?. get ( 'active_loginid' )
1835
- ?. match ( / [ a - z A - Z ] + / g)
1836
- ?. join ( '' ) ;
1837
- setTimeout ( async ( ) => {
1838
- let residence_country = '' ;
1854
+
1855
+ let residence_country = '' ;
1856
+ if ( ! isLoggedOut ) {
1839
1857
if ( this . residence ) {
1840
1858
residence_country = this . residence ;
1841
1859
} else {
@@ -1849,35 +1867,28 @@ export default class ClientStore extends BaseStore {
1849
1867
console . error ( 'Error getting residence country' , error ) ;
1850
1868
}
1851
1869
}
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
+ }
1874
1875
1875
1876
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 ,
1881
1892
} ;
1882
1893
}
1883
1894
@@ -1914,7 +1925,7 @@ export default class ClientStore extends BaseStore {
1914
1925
}
1915
1926
1916
1927
async switchAccountHandler ( ) {
1917
- if ( ! this . switched || ! this . switched . length || ! this . getAccount ( this . switched ) ?. token ) {
1928
+ if ( ! this . switched || ! this . switched . length ) {
1918
1929
if ( this . isUnableToFindLoginId ( ) ) {
1919
1930
this . handleNotFoundLoginId ( ) ;
1920
1931
return ;
@@ -1932,6 +1943,12 @@ export default class ClientStore extends BaseStore {
1932
1943
return ;
1933
1944
}
1934
1945
1946
+ const switched_account = this . getAccount ( this . switched ) ;
1947
+ if ( ! switched_account ?. token ) {
1948
+ this . handleNotFoundLoginId ( ) ;
1949
+ return ;
1950
+ }
1951
+
1935
1952
runInAction ( ( ) => ( this . is_switching = true ) ) ;
1936
1953
this . setIsAuthorize ( false ) ;
1937
1954
const from_login_id = this . loginid ;
@@ -1948,7 +1965,7 @@ export default class ClientStore extends BaseStore {
1948
1965
await BinarySocket ?. wait ( 'authorize' ) ;
1949
1966
} else {
1950
1967
await WS . forgetAll ( 'balance' ) ;
1951
- await BinarySocket . authorize ( this . getToken ( ) ) ;
1968
+ await BinarySocket . authorize ( switched_account . token ) ;
1952
1969
}
1953
1970
if ( this . root_store . common . has_error ) this . root_store . common . setError ( false , null ) ;
1954
1971
sessionStorage . setItem ( 'active_tab' , '1' ) ;
@@ -2093,7 +2110,7 @@ export default class ClientStore extends BaseStore {
2093
2110
this . initialized_broadcast = is_initialized ;
2094
2111
}
2095
2112
2096
- cleanUp ( ) {
2113
+ async cleanUp ( ) {
2097
2114
// delete all notifications keys for this account when logout
2098
2115
const notification_messages = LocalStore . getObject ( 'notification_messages' ) ;
2099
2116
if ( notification_messages && this . loginid ) {
@@ -2102,6 +2119,9 @@ export default class ClientStore extends BaseStore {
2102
2119
...notification_messages ,
2103
2120
} ) ;
2104
2121
}
2122
+ // update growthbook
2123
+ const analytics_config = await this . getAnalyticsConfig ( true ) ;
2124
+ Analytics . setAttributes ( analytics_config ) ;
2105
2125
2106
2126
this . root_store . gtm . pushDataLayer ( {
2107
2127
event : 'log_out' ,
@@ -2135,7 +2155,7 @@ export default class ClientStore extends BaseStore {
2135
2155
const response = await requestLogout ( ) ;
2136
2156
2137
2157
if ( response ?. logout === 1 ) {
2138
- this . cleanUp ( ) ;
2158
+ await this . cleanUp ( ) ;
2139
2159
2140
2160
this . setLogout ( true ) ;
2141
2161
}
0 commit comments