Skip to content

Instantly share code, notes, and snippets.

@sharu725
Last active July 5, 2024 02:17
Show Gist options
  • Save sharu725/89cfc022ec5cdd5ce35e9e8c188b3d43 to your computer and use it in GitHub Desktop.
Save sharu725/89cfc022ec5cdd5ce35e9e8c188b3d43 to your computer and use it in GitHub Desktop.
Google Analytics in Sveltekit
<!-- Change the GA ID before using this -->
<script>
let analytics = true;
if (process.env.NODE_ENV == "development") {
analytics = false;
}
</script>
<svelte:head>
{#if analytics}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-9B97ZTCYRP"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "G-9B97ZTCYRP");
</script>
{/if}
</svelte:head>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment