-
Notifications
You must be signed in to change notification settings - Fork 319
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: Incorrect Logged-In Status and Missing Residence Country in Growthbook #17966
base: master
Are you sure you want to change the base?
Changes from all commits
d72be58
2d15136
3dc9292
50ce7c7
70f0e98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,45 +17,53 @@ export const AnalyticsInitializer = async () => { | |
.then(res => res.json()) | ||
.catch(() => FIREBASE_INIT_DATA); | ||
if (process.env.RUDDERSTACK_KEY && flags?.tracking_rudderstack) { | ||
const utm_cookie = Cookies.get('utm_data'); | ||
const ppc_campaign_cookies = | ||
Cookies.getJSON('utm_data') === 'null' | ||
utm_cookie === 'null' || !utm_cookie | ||
? { | ||
utm_source: 'no source', | ||
utm_medium: 'no medium', | ||
utm_campaign: 'no campaign', | ||
utm_content: 'no content', | ||
} | ||
: Cookies.getJSON('utm_data'); | ||
: JSON.parse(utm_cookie); | ||
|
||
const client_information = Cookies.getJSON('client_information'); | ||
const client_information = Cookies.get('client_information') | ||
? JSON.parse(Cookies.get('client_information') || '') | ||
: null; | ||
const residence_country = client_information?.residence || ''; | ||
|
||
const analytics_config_config = { | ||
loggedIn: !!client_information, | ||
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: 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, | ||
network_type: navigator.connection?.effectiveType, | ||
network_rtt: navigator.connection?.rtt, | ||
network_downlink: navigator.connection?.downlink, | ||
residence_country, | ||
}; | ||
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: { | ||
loggedIn: !!client_information, | ||
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: 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, | ||
network_type: navigator.connection?.effectiveType, | ||
network_rtt: navigator.connection?.rtt, | ||
network_downlink: navigator.connection?.downlink, | ||
residence_country: client_information?.residence, | ||
...analytics_config_config, | ||
}, | ||
}, | ||
}; | ||
await Analytics?.initialise(config); | ||
Analytics.setAttributes(analytics_config_config); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the use of setAttributes here? we have initialized growthbook with same config in line 65 |
||
} | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import { redirectToLogin } from '@deriv/shared'; | ||
import Cookies from 'js-cookie'; | ||
|
||
import FIREBASE_INIT_DATA from '@deriv/api/src/remote_config.json'; | ||
import { getAppId, redirectToLogin } from '@deriv/shared'; | ||
import { getLanguage } from '@deriv/translations'; | ||
import { Analytics } from '@deriv-com/analytics'; | ||
import { | ||
OAuth2Logout, | ||
requestOidcAuthentication, | ||
TOAuth2EnabledAppList, | ||
useIsOAuth2Enabled, | ||
} from '@deriv-com/auth-client'; | ||
import { CountryUtils } from '@deriv-com/utils'; | ||
|
||
import useGrowthbookGetFeatureValue from './useGrowthbookGetFeatureValue'; | ||
|
||
|
@@ -39,9 +44,61 @@ const useOauth2 = ({ handleLogout }: { handleLogout: () => Promise<void> }) => { | |
}; | ||
|
||
const logoutHandler = async () => { | ||
if (process.env.REMOTE_CONFIG_URL) { | ||
const flags = await fetch(process.env.REMOTE_CONFIG_URL) | ||
.then(res => res.json()) | ||
.catch(() => FIREBASE_INIT_DATA); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this whole initialization again? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The attributes are not getting updated without initialization.we can check if there is a way without doing the initialization again. |
||
if (process.env.RUDDERSTACK_KEY && flags?.tracking_rudderstack) { | ||
const utm_cookie = Cookies.get('utm_data'); | ||
const ppc_campaign_cookies = | ||
utm_cookie === 'null' || !utm_cookie | ||
? { | ||
utm_source: 'no source', | ||
utm_medium: 'no medium', | ||
utm_campaign: 'no campaign', | ||
utm_content: 'no content', | ||
} | ||
: JSON.parse(utm_cookie); | ||
|
||
const analytics_config_config = { | ||
loggedIn: false, | ||
account_type: 'unlogged', | ||
app_id: String(getAppId()), | ||
device_language: navigator?.language || 'en-EN', | ||
user_language: getLanguage().toLowerCase(), | ||
country: undefined, | ||
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, | ||
network_type: navigator.connection?.effectiveType, | ||
network_rtt: navigator.connection?.rtt, | ||
network_downlink: navigator.connection?.downlink, | ||
residence_country: 'undefined', | ||
}; | ||
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: { | ||
...analytics_config_config, | ||
}, | ||
}, | ||
}; | ||
await Analytics?.initialise(config); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Q]: why do we need to initialize the whole Analytics package again? 🤔 only updating the attributes would be enough. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will work only when we re-initialize it for the logout session.can you check it and let me know if it is possible in any other way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm looking into this. will update you on this |
||
Analytics.setAttributes(analytics_config_config); | ||
|
||
// Set attributes one final time to ensure the override took effect | ||
} | ||
} | ||
// Proceed with OAuth logout | ||
await OAuth2Logout(handleLogout); | ||
}; | ||
|
||
return { isOAuth2Enabled, oAuthLogout: logoutHandler, loginHandler }; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are checking if cookie exists in line 31. So do we need
|| ''
in line 32 again?