Skip to content

Commit

Permalink
Merge pull request #1036 from near/fix_countrycookie
Browse files Browse the repository at this point in the history
fix: read cookie from cookies not local storage
  • Loading branch information
charleslavon authored Mar 7, 2024
2 parents fcab0bc + 08fc5f2 commit dc94cf8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ export function optOut(onlyRequiredCookies: boolean) {
cookieOptOut = onlyRequiredCookies;
}

function readCountryCodeCookie() {
let countryCode = '';
try {
const cc = document.cookie.split(';').filter((v) => v.indexOf('user-country-code') !== -1);
countryCode = cc.length > 0 ? cc[0].split('=')[1] : '';
} catch (e) {
console.log('failed to read user-country-code cookie', e);
}

return countryCode;
}

export async function init() {
getUserAgent();

Expand All @@ -79,7 +91,7 @@ export async function init() {
//pick up any change to cookie preferences on init (full page reload)
const userCookiePreference = localStorage.getItem('cookiesAcknowledged');
optOut(userCookiePreference === cookiePreferences.onlyRequired);
userCountryCode = localStorage.getItem('user-country-code') || '';
userCountryCode = readCountryCodeCookie();

const rudderAnalyticsKey = networkId === 'testnet' ? '2R7K9phhzpFzk2zFIq2EFBtJ8BM' : '2RIih8mrVPUTQ9uWe6TFfwXzcMe';
const rudderStackDataPlaneUrl = 'https://near.dataplane.rudderstack.com';
Expand Down

0 comments on commit dc94cf8

Please sign in to comment.