Skip to content

Instantly share code, notes, and snippets.

@sharu725
Last active December 5, 2023 22:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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