From e477246816c4ae4121e40ab40757bd29162ba426 Mon Sep 17 00:00:00 2001 From: Heather Date: Mon, 17 Jun 2024 13:50:23 -0400 Subject: [PATCH 1/2] fix: check if AWSMA exists before tracking metric --- src/utils/track.ts | 119 +++++++++++++-------------------------------- 1 file changed, 35 insertions(+), 84 deletions(-) diff --git a/src/utils/track.ts b/src/utils/track.ts index bbd75f42c79..575e55478aa 100644 --- a/src/utils/track.ts +++ b/src/utils/track.ts @@ -35,14 +35,6 @@ export const trackPageVisit = (): void => { } }; -export const trackPageFetchException = (): void => { - if (typeof window !== 'undefined' && typeof s != 'undefined') { - s.linkTrackVars = - 'prop39,prop41,prop50,prop61,prop62,eVar39,eVar41,eVar50,eVar61,eVar62,eVar69'; - s.tl(true, 'o', 'page fetch exception'); - } -}; - export const trackExternalLink = (hrefTo: string): void => { if (typeof window !== 'undefined' && typeof s != 'undefined') { s.linkTrackVars = @@ -51,57 +43,6 @@ export const trackExternalLink = (hrefTo: string): void => { } }; -export const setSearchQuery = (query: string): void => { - if (typeof window !== 'undefined' && typeof s != 'undefined') { - s.eVar26 = query; - } -}; - -const triggerNoSearchResults = (query: string): void => { - const queryBackup: string = s.eVar26; - const resultCountBackup: number = parseInt(s.eVar27, 10); - - s.eVar26 = query; - s.eVar27 = '0'; // If it's the number 0, the variable won't be sent - s.linkTrackVars = - 'prop39,prop41,prop50,prop61,prop62,eVar26,eVar27,eVar39,eVar41,eVar50,eVar61,eVar62,eVar69,events'; - s.linkTrackEvents = 'event2'; - s.events = 'event2'; - s.tl(true, 'o', 'internal search'); - - s.eVar26 = queryBackup; - s.eVar27 = resultCountBackup.toString(); -}; - -let noResultsTimeout: NodeJS.Timeout; -export const setSearchResultCount = (resultCount: number): void => { - if (typeof window !== 'undefined' && typeof s != 'undefined') { - s.eVar27 = resultCount.toString(); - s.events = resultCount === 0 ? 'event1' : 'event2'; - - if (resultCount === 0) { - if (noResultsTimeout) { - clearTimeout(noResultsTimeout); - } - noResultsTimeout = setTimeout( - triggerNoSearchResults.bind(null, s.eVar26), - 1000 - ); - } - } -}; - -export const trackSearchQuery = (_input, _event, suggestion): void => { - if (typeof window !== 'undefined' && typeof s != 'undefined') { - s.linkTrackVars = - 'prop39,prop41,prop50,prop61,prop62,eVar26,eVar27,eVar39,eVar41,eVar50,eVar61,eVar62,eVar69,events'; - s.linkTrackEvents = 'event1'; - s.events = 'event1'; - s.tl(true, 'o', 'internal search'); - } - window.location.assign(suggestion.url); -}; - export const trackFeedbackSubmission = (feedback: boolean) => { const opt = { event: { @@ -110,11 +51,13 @@ export const trackFeedbackSubmission = (feedback: boolean) => { } }; - AWSMA.ready(() => { - document.dispatchEvent( - new CustomEvent(AWSMA.TRIGGER_EVENT, { detail: opt }) - ); - }); + if (AWSMA) { + AWSMA.ready(() => { + document.dispatchEvent( + new CustomEvent(AWSMA.TRIGGER_EVENT, { detail: opt }) + ); + }); + } }; export const trackExpanderOpen = (expanderId) => { @@ -125,11 +68,13 @@ export const trackExpanderOpen = (expanderId) => { } }; - AWSMA.ready(() => { - document.dispatchEvent( - new CustomEvent(AWSMA.TRIGGER_EVENT, { detail: opt }) - ); - }); + if (AWSMA) { + AWSMA.ready(() => { + document.dispatchEvent( + new CustomEvent(AWSMA.TRIGGER_EVENT, { detail: opt }) + ); + }); + } }; export const trackCopyClicks = (data) => { @@ -141,11 +86,13 @@ export const trackCopyClicks = (data) => { data: data }; - AWSMA.ready(() => { - document.dispatchEvent( - new CustomEvent(AWSMA.TRIGGER_EVENT, { detail: opt }) - ); - }); + if (AWSMA) { + AWSMA.ready(() => { + document.dispatchEvent( + new CustomEvent(AWSMA.TRIGGER_EVENT, { detail: opt }) + ); + }); + } }; // Track the click on the "Whats new" banner component @@ -157,11 +104,13 @@ export const trackWhatsNewBanner = () => { } }; - AWSMA.ready(() => { - document.dispatchEvent( - new CustomEvent(AWSMA.TRIGGER_EVENT, { detail: opt }) - ); - }); + if (AWSMA) { + AWSMA.ready(() => { + document.dispatchEvent( + new CustomEvent(AWSMA.TRIGGER_EVENT, { detail: opt }) + ); + }); + } }; // Track the click on the Version Switcher component @@ -173,9 +122,11 @@ export const trackVersionChange = (viewOld: boolean) => { } }; - AWSMA.ready(() => { - document.dispatchEvent( - new CustomEvent(AWSMA.TRIGGER_EVENT, { detail: opt }) - ); - }); + if (AWSMA) { + AWSMA.ready(() => { + document.dispatchEvent( + new CustomEvent(AWSMA.TRIGGER_EVENT, { detail: opt }) + ); + }); + } }; From 4fa5558f1d03c6c2ecd953876201448246838672 Mon Sep 17 00:00:00 2001 From: Heather Date: Mon, 17 Jun 2024 16:59:32 -0400 Subject: [PATCH 2/2] remove unused trackWhatsNew --- src/utils/track.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/utils/track.ts b/src/utils/track.ts index 575e55478aa..57cbea1ba36 100644 --- a/src/utils/track.ts +++ b/src/utils/track.ts @@ -95,24 +95,6 @@ export const trackCopyClicks = (data) => { } }; -// Track the click on the "Whats new" banner component -export const trackWhatsNewBanner = () => { - const opt = { - event: { - type: 'click', - name: 'WhatsNewBanner' - } - }; - - if (AWSMA) { - AWSMA.ready(() => { - document.dispatchEvent( - new CustomEvent(AWSMA.TRIGGER_EVENT, { detail: opt }) - ); - }); - } -}; - // Track the click on the Version Switcher component export const trackVersionChange = (viewOld: boolean) => { const opt = {