diff --git a/scripts/delayed.js b/scripts/delayed.js index 4f632597..5a5e663b 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -4,4 +4,33 @@ import { sampleRUM } from './aem.js'; // Core Web Vitals RUM collection sampleRUM('cwv'); -// add more delayed functionality here +// google tag manager -start +function loadGTM() { + const scriptTag = document.createElement('script'); + scriptTag.innerHTML = ` + let gtmId = 'GTM-MLWV3QQ'; + // googleTagManager + (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.prepend(scriptTag); +} +// google tag manager -end + +if ( + !window.location.hostname.includes('localhost') + && !document.location.hostname.includes('.hlx.page') +) { + loadGTM(); +}