Skip to content

Commit

Permalink
Load Launch Script Eager
Browse files Browse the repository at this point in the history
  • Loading branch information
andreituicu committed Apr 14, 2024
1 parent a8fc23a commit 95f3087
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
32 changes: 1 addition & 31 deletions aemeds/scripts/delayed.js
Original file line number Diff line number Diff line change
@@ -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();
29 changes: 29 additions & 0 deletions aemeds/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down Expand Up @@ -505,6 +533,7 @@ async function loadEager(doc) {
if (!LCP_WAIT_SKIP_TEMPLATE.includes(getTemplate())) {
await waitForLCP(LCP_BLOCKS);
}
loadAdobeDTM();
}

try {
Expand Down

0 comments on commit 95f3087

Please sign in to comment.