Skip to content

Commit

Permalink
TDW-2277 code cleanup and added fetchplaceholders in delayedjs
Browse files Browse the repository at this point in the history
  • Loading branch information
bosco-ensemble committed Apr 9, 2024
1 parent 7a24724 commit 888af82
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
5 changes: 2 additions & 3 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
47 changes: 23 additions & 24 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 888af82

Please sign in to comment.