One build per environment: PROD_* variables for the production artifact, TEST_* for the test build and the CSP check. The build fails when a variable is empty. Tests use the production values from config/monitoringTestEnv.ts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { monitoringFor } 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 }: { hostname?: string }) {
|
|
useEffect(() => {
|
|
// Read here, not as a default parameter: there is no window while
|
|
// prerendering
|
|
const host = hostname ?? window.location.hostname;
|
|
const monitoring = monitoringFor(host);
|
|
if (!monitoring || document.getElementById(SCRIPT_ELEMENT_ID)) return;
|
|
|
|
const script = document.createElement('script');
|
|
script.id = SCRIPT_ELEMENT_ID;
|
|
script.src = monitoring.umamiScriptUrl;
|
|
script.defer = true;
|
|
script.dataset.websiteId = monitoring.umamiWebsiteId;
|
|
script.dataset.domains = host;
|
|
script.dataset.doNotTrack = 'true';
|
|
document.head.appendChild(script);
|
|
|
|
return () => script.remove();
|
|
}, [hostname]);
|
|
|
|
return null;
|
|
}
|