Skip to content

Commit

Permalink
Included GTM script
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeepgera23 committed Oct 13, 2023
1 parent 278cebe commit 05417a5
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 05417a5

Please sign in to comment.