Skip to content

Commit

Permalink
feat(layout): add analytics via goatcounter
Browse files Browse the repository at this point in the history
  • Loading branch information
jmiguelv committed Nov 5, 2024
1 parent 845523f commit 9c879fe
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<script lang="ts">
import { dev } from '$app/environment';
import { page } from '$app/stores';
import Breadcrumbs from '$lib/components/Breadcrumbs.svelte';
import Footer from '$lib/components/Footer.svelte';
import Head from '$lib/components/Head.svelte';
import Header from '$lib/components/Header.svelte';
import PageTransition from '$lib/components/Transition.svelte';
import { onMount } from 'svelte';
import 'open-props/style';
import 'open-props/normalize';
Expand All @@ -13,6 +15,32 @@
export let data;
function shouldTrack() {
if (navigator.doNotTrack === '1' || navigator.doNotTrack === 'yes') {
return false;
}
return true;
}
function initGoatCounter() {
if (!shouldTrack()) return;
const script = document.createElement('script');
script.dataset.goatcounter = 'https://kingspast.goatcounter.com/count';
script.src = '//gc.zgo.at/count.js';
script.async = true;
script.onerror = () => console.warn('Failed to load GoatCounter');
document.body.appendChild(script);
}
onMount(() => {
if (!dev && shouldTrack()) {
initGoatCounter();
}
});
$: metadata = $page.data?._metadata || {};
</script>

Expand Down

0 comments on commit 9c879fe

Please sign in to comment.