From 5b231145f1ee90428df79bf08ae64a297f20606a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20Engstr=C3=B6m?= Date: Thu, 14 Nov 2024 13:44:37 +0100 Subject: [PATCH] fix(lxlweb): prevent error when missing matomo-id (#1160) * fix(lxlweb): prevent error when missing matomo-id --- lxl-web/src/lib/components/CookieConsent.svelte | 6 +++--- lxl-web/src/lib/contexts/matomo.ts | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lxl-web/src/lib/components/CookieConsent.svelte b/lxl-web/src/lib/components/CookieConsent.svelte index 869e6ae32..e78a595ba 100644 --- a/lxl-web/src/lib/components/CookieConsent.svelte +++ b/lxl-web/src/lib/components/CookieConsent.svelte @@ -36,14 +36,14 @@ }, onConsent: ({ cookie }) => { if (cookie.categories.includes('analytics')) { - $matomoTracker.rememberConsentGiven(); + $matomoTracker?.rememberConsentGiven(); } }, onChange: ({ cookie }) => { if (cookie.categories.includes('analytics')) { - $matomoTracker.rememberConsentGiven(); + $matomoTracker?.rememberConsentGiven(); } else { - $matomoTracker.forgetConsentGiven(); + $matomoTracker?.forgetConsentGiven(); } }, language: { diff --git a/lxl-web/src/lib/contexts/matomo.ts b/lxl-web/src/lib/contexts/matomo.ts index 6da70a4f3..be7503b70 100644 --- a/lxl-web/src/lib/contexts/matomo.ts +++ b/lxl-web/src/lib/contexts/matomo.ts @@ -5,7 +5,7 @@ import { type Writable } from 'svelte/store'; import { type MatomoTracker } from '$lib/types/matomo'; import { setContext, getContext } from 'svelte'; -const MATOMO_ID: number = +env.PUBLIC_MATOMO_ID; +const MATOMO_ID = env.PUBLIC_MATOMO_ID && +env.PUBLIC_MATOMO_ID; const tracker = writable(); @@ -29,7 +29,6 @@ export function setMatomoTracker() { const initializedMatomoTracker = initMatomo(); if (initializedMatomoTracker) { tracker.set(initializedMatomoTracker); - console.info('Matomo tracker set'); } }