diff --git a/lxl-web/src/lib/components/Matomo.svelte b/lxl-web/src/lib/components/Matomo.svelte index 8d063fc78..e96791843 100644 --- a/lxl-web/src/lib/components/Matomo.svelte +++ b/lxl-web/src/lib/components/Matomo.svelte @@ -1,14 +1,20 @@ {#if URL} - + {/if} diff --git a/lxl-web/src/lib/contexts/matomo.ts b/lxl-web/src/lib/contexts/matomo.ts index 0588b0a21..8fff5458c 100644 --- a/lxl-web/src/lib/contexts/matomo.ts +++ b/lxl-web/src/lib/contexts/matomo.ts @@ -7,6 +7,8 @@ import { setContext, getContext } from 'svelte'; const MATOMO_ID: number = +env.PUBLIC_MATOMO_ID; +const tracker = writable(); + function initMatomo() { if (browser) { const matomo = window.Matomo; @@ -16,6 +18,7 @@ function initMatomo() { if (tracker) { tracker.disableCookies(); // TODO - remove when cookie consent implemented tracker.enableLinkTracking(); + tracker.trackPageView(); return tracker; } } @@ -25,11 +28,16 @@ function initMatomo() { export function setMatomoTracker() { const initializedMatomoTracker = initMatomo(); if (initializedMatomoTracker) { - const tracker = writable(initializedMatomoTracker); - setContext('matomo', tracker); + tracker.set(initializedMatomoTracker); + console.info('Matomo tracker set'); } } +export function setMatomoContext() { + setMatomoTracker(); + setContext('matomo', tracker); +} + export function getMatomoTracker() { return getContext>('matomo'); }