Files
AndreaSlopFotografie/web/src/components/Analytics/UmamiAnalytics.tsx
T
SluijsensandClaude Opus 5.5 6d3a1566c2
Continuous Integration / lighthouse (pull_request) Canceled after 0s
Continuous Integration / deploy-test (pull_request) Canceled after 0s
Continuous Integration / deploy-production (pull_request) Canceled after 0s
Continuous Integration / check (pull_request) Canceled after 2m22s
Adds Sentry and Umami monitoring to the site
Sentry loads after the page and reports errors only, without personal data;
Umami counts visits per environment. Both only run on andreaslop.nl and
test.andreaslop.nl. The CSP allows just these two hosts, and builds carry the
commit SHA as release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 12:08:47 +02:00

32 lines
1.1 KiB
TypeScript

import { useEffect } from 'react';
import { monitoringFor, umamiOrigin } from '@/monitoring/config';
const SCRIPT_ELEMENT_ID = 'umami-analytics-script';
// Bezoekersstatistieken zonder cookies (M6). Alleen op een bekende host, met
// de website van die omgeving; data-domains telt nergens anders mee en
// data-do-not-track respecteert de Do Not Track-instelling van de browser.
export default function UmamiAnalytics({
hostname = window.location.hostname,
}: {
hostname?: string;
}) {
useEffect(() => {
const monitoring = monitoringFor(hostname);
if (!monitoring || document.getElementById(SCRIPT_ELEMENT_ID)) return;
const script = document.createElement('script');
script.id = SCRIPT_ELEMENT_ID;
script.src = `${umamiOrigin}/script.js`;
script.defer = true;
script.dataset.websiteId = monitoring.umamiWebsiteId;
script.dataset.domains = hostname;
script.dataset.doNotTrack = 'true';
document.head.appendChild(script);
return () => script.remove();
}, [hostname]);
return null;
}