Skip to content

Commit

Permalink
fix(lxlweb): prevent error when missing matomo-id (#1160)
Browse files Browse the repository at this point in the history
* fix(lxlweb): prevent error when missing matomo-id
  • Loading branch information
jesperengstrom authored Nov 14, 2024
1 parent 75e5cba commit 5b23114
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lxl-web/src/lib/components/CookieConsent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
3 changes: 1 addition & 2 deletions lxl-web/src/lib/contexts/matomo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MatomoTracker>();

Expand All @@ -29,7 +29,6 @@ export function setMatomoTracker() {
const initializedMatomoTracker = initMatomo();
if (initializedMatomoTracker) {
tracker.set(initializedMatomoTracker);
console.info('Matomo tracker set');
}
}

Expand Down

0 comments on commit 5b23114

Please sign in to comment.