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-2277 Decrease ad load times #120

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,7 @@
if (userButton) userButton.replaceWith(userButton.cloneNode(true));
const favoriteButtons = document.querySelectorAll('.leaderboard-favorite-button');
if (favoriteButtons) favoriteButtons.forEach((btn) => btn.replaceWith(btn.cloneNode(true)));
loadScript(
'https://cdns.gigya.com/JS/socialize.js?apikey=3__4H034SWkmoUfkZ_ikv8tqNIaTA0UIwoX5rsEk96Ebk5vkojWtKRZixx60tZZdob',
setupGigya,
);
loadScript('https://cdns.gigya.com/JS/socialize.js?apikey=3__4H034SWkmoUfkZ_ikv8tqNIaTA0UIwoX5rsEk96Ebk5vkojWtKRZixx60tZZdob', setupGigya);
}

initGigya();
Expand Down Expand Up @@ -660,7 +657,8 @@
return null;
}

async function OptanonWrapper() {
const OptanonWrapper = (async function () {

Check warning on line 660 in scripts/delayed.js

View workflow job for this annotation

GitHub Actions / build

Unexpected unnamed async function
console.log('test');

Check warning on line 661 in scripts/delayed.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
const geoInfo = window.Optanon.getGeolocationData();
Object.keys(geoInfo).forEach((key) => {
const cookieName = `PGAT_${key.charAt(0).toUpperCase() + key.slice(1)}`;
Expand All @@ -681,39 +679,41 @@
}
}
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':
});

export const loadAds = (function () {

Check warning on line 684 in scripts/delayed.js

View workflow job for this annotation

GitHub Actions / build

Unexpected unnamed function
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);
document.head.append(GTMScript);

const GTMFrame = document.createElement('no-script');
GTMFrame.innerHTML = `<iframe src="https://www.googletagmanager.com/ns.html?id=${gtmId}"
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);
}
document.body.prepend(GTMFrame);
}

window.OptanonWrapper = OptanonWrapper;
window.OptanonWrapper = OptanonWrapper;

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

async function loadLiveChat() {
const liveChat = getMetadata('live-chat');
Expand Down
4 changes: 4 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
* governing permissions and limitations under the License.
*/

// eslint-disable-next-line import/no-cycle
import { loadAds } from './delayed.js';

/**
* log RUM if part of the sample.
* @param {string} checkpoint identifies the checkpoint in funnel
Expand Down Expand Up @@ -1069,6 +1072,7 @@ async function loadLazy(doc) {
addFavIcon(`${window.hlx.codeBasePath}/styles/favicon.ico`);

doc.querySelectorAll('div:not([class]):not([id]):empty').forEach((empty) => empty.remove());
loadAds();
}

/**
Expand Down
Loading