From 95f3087541d36d10a84e4a9b9120646b14fa61a4 Mon Sep 17 00:00:00 2001 From: Andrei Tuicu Date: Sun, 14 Apr 2024 21:43:22 +0200 Subject: [PATCH 1/2] Load Launch Script Eager --- aemeds/scripts/delayed.js | 32 +------------------------------- aemeds/scripts/scripts.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/aemeds/scripts/delayed.js b/aemeds/scripts/delayed.js index 2c41e226..5903af24 100644 --- a/aemeds/scripts/delayed.js +++ b/aemeds/scripts/delayed.js @@ -1,35 +1,5 @@ // eslint-disable-next-line import/no-cycle -import { loadScript, sampleRUM } from './aem.js'; +import { sampleRUM } from './aem.js'; // Core Web Vitals RUM collection sampleRUM('cwv'); -// add more delayed functionality here -async function loadAdobeDTM() { - await loadScript(`${window.hlx.codeBasePath}/scripts/jquery-3.7.1.min.js`); - const prod = 'https://assets.adobedtm.com/a441b904b50e/7a4facbbcffb/launch-039be8795dc8.min.js'; - const stage = 'https://assets.adobedtm.com/a441b904b50e/7a4facbbcffb/launch-a2ae4c3b0523-staging.min.js'; - - const searchParams = new URLSearchParams(window.location.search); - const env = searchParams.get('launch'); - if (env === 'prod') { - loadScript(prod, { async: '' }); - return; - } - - if (env === 'stage') { - loadScript(stage, { async: '' }); - return; - } - - const { host } = window.location; - if (host === 'servicenow.com' || host === 'www.servicenow.com') { - loadScript(prod, { async: '' }); - } else { - if (searchParams.get('disableLaunch') === 'true') { - return; - } - loadScript(stage, { async: '' }); - } -} - -loadAdobeDTM(); diff --git a/aemeds/scripts/scripts.js b/aemeds/scripts/scripts.js index 1f7e2e19..5a7fe599 100644 --- a/aemeds/scripts/scripts.js +++ b/aemeds/scripts/scripts.js @@ -32,6 +32,34 @@ export function getTemplate() { return toClassName(getMetadata('template')); } +async function loadAdobeDTM() { + await loadScript(`${window.hlx.codeBasePath}/scripts/jquery-3.7.1.min.js`); + const prod = 'https://assets.adobedtm.com/a441b904b50e/7a4facbbcffb/launch-039be8795dc8.min.js'; + const stage = 'https://assets.adobedtm.com/a441b904b50e/7a4facbbcffb/launch-a2ae4c3b0523-staging.min.js'; + + const searchParams = new URLSearchParams(window.location.search); + const env = searchParams.get('launch'); + if (env === 'prod') { + loadScript(prod, { async: '' }); + return; + } + + if (env === 'stage') { + loadScript(stage, { async: '' }); + return; + } + + const { host } = window.location; + if (host === 'servicenow.com' || host === 'www.servicenow.com') { + loadScript(prod, { async: '' }); + } else { + if (searchParams.get('disableLaunch') === 'true') { + return; + } + loadScript(stage, { async: '' }); + } +} + export function getAnalyticsSiteName() { return 'SN Blogs'; } @@ -505,6 +533,7 @@ async function loadEager(doc) { if (!LCP_WAIT_SKIP_TEMPLATE.includes(getTemplate())) { await waitForLCP(LCP_BLOCKS); } + loadAdobeDTM(); } try { From 81102dec9aca1940a457457494d6f5407411580c Mon Sep 17 00:00:00 2001 From: Andrei Tuicu Date: Sun, 14 Apr 2024 21:44:01 +0200 Subject: [PATCH 2/2] Load Launch Script Eager --- aemeds/scripts/scripts.js | 1 + 1 file changed, 1 insertion(+) diff --git a/aemeds/scripts/scripts.js b/aemeds/scripts/scripts.js index 5a7fe599..9ec1b2d1 100644 --- a/aemeds/scripts/scripts.js +++ b/aemeds/scripts/scripts.js @@ -15,6 +15,7 @@ import { waitForLCP, loadBlock, readBlockConfig, + loadScript, } from './aem.js'; import { a, div, p, span,