Last active
October 31, 2022 11:56
-
-
Save devmnj/ae60f3975fc4f36e7de8f42e38bbe009 to your computer and use it in GitHub Desktop.
Svelete Analytic Component
This file contains hidden or 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
Place the component in +layout.svelte | |
<script lang="ts"> | |
import { page } from '$app/stores' | |
$: { | |
if (typeof gtag !== 'undefined') { | |
gtag('config', 'MEASUREMENT_ID', { | |
page_title: document.title, | |
page_path: $page.url.pathname, | |
}) | |
} | |
} | |
</script> | |
<svelte:head> | |
<script | |
async | |
src="https://www.googletagmanager.com/gtag/js?id=MEASUREMENT_ID"> | |
</script> | |
<script> | |
window.dataLayer = window.dataLayer || [] | |
function gtag() { | |
dataLayer.push(arguments) | |
} | |
gtag('js', new Date()) | |
gtag('config', 'MEASUREMENT_ID') | |
</script> | |
</svelte:head> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment