Skip to content

Commit

Permalink
feat: provide country code in product analytics for opted-in users
Browse files Browse the repository at this point in the history
  • Loading branch information
charleslavon committed Mar 5, 2024
1 parent 2d91b50 commit 619ea3a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let pendingEvents: any = [];
let cookieOptOut = false;
export const cookiePreferences = { onlyRequired: 'only_required', all: 'all' };
let clientsideReferrer = '';
let userCountryCode = '';

declare global {
interface Window {
Expand Down Expand Up @@ -78,6 +79,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') || '';

const rudderAnalyticsKey = networkId === 'testnet' ? '2R7K9phhzpFzk2zFIq2EFBtJ8BM' : '2RIih8mrVPUTQ9uWe6TFfwXzcMe';
const rudderStackDataPlaneUrl = 'https://near.dataplane.rudderstack.com';
Expand Down Expand Up @@ -126,6 +128,7 @@ export function recordPageView(pageName: string) {
userAgentDetail,
ref: filterURL(document.referrer),
clientsideReferrer,
userCountryCode,
});
} catch (e) {
console.error(e);
Expand All @@ -140,6 +143,7 @@ const record = (eventType: string, e: UIEvent | PointerEvent) => {
xPath: getXPath(e.target as HTMLElement),
componentSrc: getComponentName(e.target as HTMLElement),
clientsideReferrer,
userCountryCode,
});
};
export const recordClick = (e: UIEvent | PointerEvent) => record('click', e);
Expand Down Expand Up @@ -176,6 +180,7 @@ export function recordEventWithProps(eventLabel: string, properties: Record<stri
hashId: localStorage.getItem('hashId'),
anonymousUserIdCreatedAt,
clientsideReferrer,
userCountryCode,
});
} catch (e) {
console.error(e);
Expand All @@ -195,6 +200,7 @@ export function recordEvent(eventLabel: string) {
userAgentDetail,
anonymousUserIdCreatedAt,
clientsideReferrer,
userCountryCode,
});
} catch (e) {
console.error(e);
Expand Down

0 comments on commit 619ea3a

Please sign in to comment.