Skip to content

Commit

Permalink
Merge pull request #14 from hlxsites/feature/gtm-onetrust-cookie
Browse files Browse the repository at this point in the history
Included GTM script
  • Loading branch information
pardeepgera23 authored Oct 14, 2023
2 parents 278cebe + 05417a5 commit d1a9dd7
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit d1a9dd7

Please sign in to comment.