Skip to content

Instantly share code, notes, and snippets.

@chientrm
Created January 25, 2024 06:44
Show Gist options
  • Save chientrm/087941c83d633840a1de8d5c3a8912e6 to your computer and use it in GitHub Desktop.
Save chientrm/087941c83d633840a1de8d5c3a8912e6 to your computer and use it in GitHub Desktop.
SvelteKit Google Tag Manager
onMount(() => {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
const gtmScript = document.createElement('script');
gtmScript.src = 'https://www.googletagmanager.com/gtm.js?id=' + PUBLIC_TAG_ID;
document.head.append(gtmScript);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment