Skip to content

Commit

Permalink
update analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
westerandr committed Apr 26, 2024
1 parent 4594d5f commit cbab657
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
23 changes: 15 additions & 8 deletions src/lib/components/Analytics.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<script>
import { onMount } from 'svelte';
export let measurementId;
import { onMount } from 'svelte';
onMount(() => {
window.dataLayer = window.dataLayer || [];
function gtag() {
window.dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', measurementId);
let script1 = document.createElement('script');
script1.src = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`;
script1.async = true;
document.head.appendChild(script1);
let script2 = document.createElement('script');
script2.innerHTML = `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${measurementId}');
`;
document.head.appendChild(script2);
});
</script>
1 change: 0 additions & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<title>Samoa Code Hub</title>
</svelte:head>
{#if gaMesurementId}
<script async src="https://www.googletagmanager.com/gtag/js?id={gaMesurementId}"></script>
<Analytics measurementId={gaMesurementId} />
{/if}
<!-- App Shell -->
Expand Down

0 comments on commit cbab657

Please sign in to comment.