From 619ea3a0a1cd35e2f11b469e2ebae710650a69db Mon Sep 17 00:00:00 2001 From: Charles Garrett Date: Tue, 5 Mar 2024 17:04:58 -0500 Subject: [PATCH] feat: provide country code in product analytics for opted-in users --- src/utils/analytics.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/utils/analytics.ts b/src/utils/analytics.ts index 45cb20799..5d4909f42 100644 --- a/src/utils/analytics.ts +++ b/src/utils/analytics.ts @@ -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 { @@ -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'; @@ -126,6 +128,7 @@ export function recordPageView(pageName: string) { userAgentDetail, ref: filterURL(document.referrer), clientsideReferrer, + userCountryCode, }); } catch (e) { console.error(e); @@ -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); @@ -176,6 +180,7 @@ export function recordEventWithProps(eventLabel: string, properties: Record