From 888af82e93745f24c75755c715009262879000f4 Mon Sep 17 00:00:00 2001 From: bosco-ensemble Date: Mon, 8 Apr 2024 18:19:25 -0700 Subject: [PATCH] TDW-2277 code cleanup and added fetchplaceholders in delayedjs --- scripts/delayed.js | 5 ++--- scripts/scripts.js | 47 +++++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/scripts/delayed.js b/scripts/delayed.js index 1cc88dda..6cb855e0 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -3,14 +3,13 @@ import { decorateIcons, fetchPlaceholders, sampleRUM, - decorateBlock, - loadBlock, loadScript, getMetadata, fetchGraphQL, - sendAnalyticsPageEvent, } from './scripts.js'; +const placeholders = await fetchPlaceholders(); + // Core Web Vitals RUM collection sampleRUM('cwv'); diff --git a/scripts/scripts.js b/scripts/scripts.js index ed14a19b..4ada6548 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -1148,6 +1148,29 @@ function getCookie(cookieName) { return null; } +export async function sendAnalyticsPageEvent() { + window.dataLayer = window.dataLayer || []; + const dl = window.dataLayer; + const placeholders = await fetchPlaceholders(); + const isUserLoggedIn = window.gigyaAccountInfo && window.gigyaAccountInfo != null + && window.gigyaAccountInfo.errorCode === 0; + + const { pageName, sections } = getPageNameAndSections(); + dl.push({ + event: 'pageload', + pageName, + pageUrl: window.location.href, + siteSection: sections[0] || '', + siteSubSection: sections[1] || '', + siteSubSection2: sections[2] || '', + gigyaID: isUserLoggedIn && window.gigyaAccountInfo.UID ? window.gigyaAccountInfo.UID : '', + userLoggedIn: isUserLoggedIn ? 'Logged In' : 'Logged Out', + tourName: placeholders.tourName.toLowerCase().replaceAll(' ', '_'), + tournamentID: `${placeholders.tourCode.toUpperCase()}${placeholders.currentYear}${placeholders.tournamentId}`, + ipAddress: '127.0.0.1', + deviceType: 'Web', + }); +} async function OptanonWrapper() { const geoInfo = window.Optanon.getGeolocationData(); Object.keys(geoInfo).forEach((key) => { @@ -1212,30 +1235,6 @@ async function loadAds(doc) { } } -export async function sendAnalyticsPageEvent() { - window.dataLayer = window.dataLayer || []; - const dl = window.dataLayer; - const placeholders = await fetchPlaceholders(); - const isUserLoggedIn = window.gigyaAccountInfo && window.gigyaAccountInfo != null - && window.gigyaAccountInfo.errorCode === 0; - - const { pageName, sections } = getPageNameAndSections(); - dl.push({ - event: 'pageload', - pageName, - pageUrl: window.location.href, - siteSection: sections[0] || '', - siteSubSection: sections[1] || '', - siteSubSection2: sections[2] || '', - gigyaID: isUserLoggedIn && window.gigyaAccountInfo.UID ? window.gigyaAccountInfo.UID : '', - userLoggedIn: isUserLoggedIn ? 'Logged In' : 'Logged Out', - tourName: placeholders.tourName.toLowerCase().replaceAll(' ', '_'), - tournamentID: `${placeholders.tourCode.toUpperCase()}${placeholders.currentYear}${placeholders.tournamentId}`, - ipAddress: '127.0.0.1', - deviceType: 'Web', - }); -} - try { const hidden = Symbol('hidden'); const proxy = Symbol('proxy');