Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TDW-2152 Update Ad Speed and Parameters #108

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
13 changes: 11 additions & 2 deletions blocks/marketing/marketing.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,23 @@ export default async function decorate(block) {
window.tude = window.tude || { cmd: [] };
loadScript('https://www.googletagservices.com/tag/js/gpt.js', () => {
loadScript(`https://dn0qt3r0xannq.cloudfront.net/${placeholders.adsPath}/prebid-load.js`, () => {
// loadScript(`https://web.prebidwrapper.com/${placeholders.adsPath}/prebid-load.js`, () => {
let pageName = window.location.pathname.slice(1);
if (!pageName) {
pageName = 'homepage';
} else if (pageName.startsWith('news')) {
pageName = 'news';
} if (pageName.includes('/')) {
pageName = pageName.substring(pageName.lastIndexOf('/') + 1);
}
window.tude.cmd.push(() => {
window.tude.setDeviceType(getDevice()); // optional
window.tude.setPageTargeting({ // optional
url_path: window.location.origin,
s1: placeholders.adsS1,
s2: placeholders.adsS2,
s3: placeholders.adsS3,
s4: pageName,
pos: 'midcontent',
m_data: '0',
m_safety: 'safe',
m_catagories: 'moat_safe',
Expand All @@ -59,7 +68,7 @@ export default async function decorate(block) {
kuid: '',
aid: '20767395437692810572475817725693908164',
});
window.tude.setAdUnitPath(`/${placeholders.adsNetwork}/pgat.${getDevice() === 'mobile' ? 'phone' : getDevice()}/pgatour`);
window.tude.setAdUnitPath(`/${placeholders.adsNetwork}/pgatour-web/pgatour`);
});
window.tude.cmd.push(() => {
document.querySelectorAll('.ad').forEach((ad) => {
Expand Down
72 changes: 0 additions & 72 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ import {
decorateIcons,
fetchPlaceholders,
sampleRUM,
decorateBlock,
loadBlock,
loadScript,
getMetadata,
fetchGraphQL,
sendAnalyticsPageEvent,
} from './scripts.js';

const placeholders = await fetchPlaceholders();
Expand Down Expand Up @@ -646,75 +643,6 @@ async function populateStatusBar(statusBar) {

populateStatusBar(document.querySelector('header > .status-bar'));

/* setup cookie preferences */
function getCookie(cookieName) {
const name = `${cookieName}=`;
const decodedCookie = decodeURIComponent(document.cookie);
const split = decodedCookie.split(';');
// eslint-disable-next-line no-plusplus
for (let i = 0; i < split.length; i++) {
let c = split[i];
while (c.charAt(0) === ' ') c = c.substring(1);
if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
}
return null;
}

async function OptanonWrapper() {
const geoInfo = window.Optanon.getGeolocationData();
Object.keys(geoInfo).forEach((key) => {
const cookieName = `PGAT_${key.charAt(0).toUpperCase() + key.slice(1)}`;
const cookie = getCookie(cookieName);
if (!cookie || cookie !== geoInfo[key]) document.cookie = `${cookieName}=${geoInfo[key]}`;
});

const prevOptIn = localStorage.getItem('OptIn_PreviousPermissions');
if (prevOptIn) {
try {
const settings = JSON.parse(prevOptIn);
if (settings.tempImplied) {
localStorage.removeItem('OptIn_PreviousPermissions');
}
} catch (e) {
// eslint-disable-next-line no-console
console.error('OptIn_PreviousPermissions parse failed');
}
}
sendAnalyticsPageEvent();
}

const otId = placeholders.onetrustId;
if (otId) {
const cookieScript = loadScript('https://cdn.cookielaw.org/scripttemplates/otSDKStub.js');
cookieScript.setAttribute('data-domain-script', `${otId}${isProd ? '' : '-test'}`);
cookieScript.setAttribute('data-dlayer-name', 'dataLayer');
cookieScript.setAttribute('data-nscript', 'beforeInteractive');

const gtmId = placeholders.googletagmanagerId;
if (gtmId) {
const GTMScript = document.createElement('script');
GTMScript.innerHTML = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${gtmId}');`;
document.head.append(GTMScript);

const GTMFrame = document.createElement('no-script');
GTMFrame.innerHTML = `<iframe src="https://www.googletagmanager.com/ns.html?id=${gtmId}"
height="0" width="0" style="display:none;visibility:hidden"></iframe>`;
document.body.prepend(GTMFrame);
}

window.OptanonWrapper = OptanonWrapper;

if (document.querySelector('.marketing')) {
const marketingBlock = document.querySelector('.marketing');
decorateBlock(marketingBlock);
loadBlock(marketingBlock);
}
}

async function loadLiveChat() {
const liveChat = getMetadata('live-chat');
if (liveChat && ['yes', 'on', 'true'].includes(liveChat.toLowerCase())) {
Expand Down
80 changes: 80 additions & 0 deletions scripts/dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// eslint-disable-next-line import/no-cycle
import {
decorateBlock,
fetchPlaceholders,
loadBlock,
loadScript,
sendAnalyticsPageEvent,
} from './scripts.js';

const placeholders = await fetchPlaceholders();
const isProd = window.location.hostname.endsWith(placeholders.hostname);

/* setup cookie preferences */
function getCookie(cookieName) {
const name = `${cookieName}=`;
const decodedCookie = decodeURIComponent(document.cookie);
const split = decodedCookie.split(';');
// eslint-disable-next-line no-plusplus
for (let i = 0; i < split.length; i++) {
let c = split[i];
while (c.charAt(0) === ' ') c = c.substring(1);
if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
}
return null;
}

async function OptanonWrapper() {
const geoInfo = window.Optanon.getGeolocationData();
Object.keys(geoInfo).forEach((key) => {
const cookieName = `PGAT_${key.charAt(0).toUpperCase() + key.slice(1)}`;
const cookie = getCookie(cookieName);
if (!cookie || cookie !== geoInfo[key]) document.cookie = `${cookieName}=${geoInfo[key]}`;
});

const prevOptIn = localStorage.getItem('OptIn_PreviousPermissions');
if (prevOptIn) {
try {
const settings = JSON.parse(prevOptIn);
if (settings.tempImplied) {
localStorage.removeItem('OptIn_PreviousPermissions');
}
} catch (e) {
// eslint-disable-next-line no-console
console.error('OptIn_PreviousPermissions parse failed');
}
}
sendAnalyticsPageEvent();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, we can remove this function because we are not using it in GTM to fire page load events

}

const otId = placeholders.onetrustId;
if (otId) {
const cookieScript = loadScript('https://cdn.cookielaw.org/scripttemplates/otSDKStub.js');
cookieScript.setAttribute('data-domain-script', `${otId}${isProd ? '' : '-test'}`);
cookieScript.setAttribute('data-dlayer-name', 'dataLayer');
cookieScript.setAttribute('data-nscript', 'beforeInteractive');

const gtmId = placeholders.googletagmanagerId;
if (gtmId) {
const GTMScript = document.createElement('script');
GTMScript.innerHTML = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${gtmId}');`;
document.head.append(GTMScript);

const GTMFrame = document.createElement('no-script');
GTMFrame.innerHTML = `<iframe src="https://www.googletagmanager.com/ns.html?id=${gtmId}"
height="0" width="0" style="display:none;visibility:hidden"></iframe>`;
document.body.prepend(GTMFrame);
}

window.OptanonWrapper = OptanonWrapper;

if (document.querySelector('.marketing')) {
const marketingBlock = document.querySelector('.marketing');
decorateBlock(marketingBlock);
loadBlock(marketingBlock);
}
}
10 changes: 10 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1052,10 +1052,20 @@ async function loadEager(doc) {
}
}

/**
* Loads everything that required HTML to be in place.
*/
function loadDependencies() {
// eslint-disable-next-line import/no-cycle
import('./dependencies.js');
}

/**
* loads everything that doesn't need to be delayed.
*/
async function loadLazy(doc) {
loadDependencies();

const main = doc.querySelector('main');
await loadBlocks(main);

Expand Down
1 change: 1 addition & 0 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ main .ad {
align-items: center;
justify-content: center;
margin: 32px 0;
overflow: hidden;
}

main .ad .ad-top {
Expand Down
Loading