Skip to content

Commit

Permalink
Add Adobe Launch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian committed Apr 16, 2024
1 parent ca3ebe8 commit 814985f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
14 changes: 13 additions & 1 deletion scripts/delayed.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
// eslint-disable-next-line import/no-cycle
import { loadCSS, sampleRUM } from './lib-franklin.js';
import { loadCSS, loadScript, sampleRUM } from './lib-franklin.js';

// Core Web Vitals RUM collection
sampleRUM('cwv');

// add more delayed functionality here

async function loadAdobeLaunch() {
const adobedtmSrc = 'https://assets.adobedtm.com/9273d4aedcd2/6eb97addd328/launch-1dd947b3f935.min.js';

await loadScript(adobedtmSrc, {
type: 'text/javascript',
async: true,
});
}

store.emit('delayed:loaded');

loadCSS(`${window.hlx.codeBasePath}/styles/icons.css`);

await loadAdobeLaunch();
25 changes: 25 additions & 0 deletions scripts/lib-franklin.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@ export function loadCSS(href, callback) {
}
}

/**
* Loads a non module JS file.
* @param {string} src URL to the JS file
* @param {Object} attrs additional optional attributes
*/
export async function loadScript(src, attrs) {
return new Promise((resolve, reject) => {
if (!document.querySelector(`head > script[src="${src}"]`)) {
const script = document.createElement('script');
script.src = src;
if (attrs) {
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const attr in attrs) {
script.setAttribute(attr, attrs[attr]);
}
}
script.onload = resolve;
script.onerror = reject;
document.head.append(script);
} else {
resolve();
}
});
}

/**
* Retrieves the content of metadata tags.
* @param {string} name The metadata name (or property)
Expand Down

0 comments on commit 814985f

Please sign in to comment.