Last active
July 5, 2024 02:17
-
-
Save sharu725/89cfc022ec5cdd5ce35e9e8c188b3d43 to your computer and use it in GitHub Desktop.
Google Analytics in Sveltekit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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