Adds Sentry and Umami monitoring to the site
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
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
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>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { render } from '@testing-library/react';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import UmamiAnalytics from './UmamiAnalytics';
|
||||
|
||||
const umamiScripts = () =>
|
||||
document.querySelectorAll<HTMLScriptElement>(
|
||||
'script[src="https://analytics.slpsoftware.nl/script.js"]',
|
||||
);
|
||||
|
||||
afterEach(() => {
|
||||
umamiScripts().forEach((script) => script.remove());
|
||||
});
|
||||
|
||||
describe('UmamiAnalytics', () => {
|
||||
it('voegt geen script toe op een onbekende host', () => {
|
||||
render(<UmamiAnalytics hostname="localhost" />);
|
||||
expect(umamiScripts()).toHaveLength(0);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['andreaslop.nl', '3edbb7d1-4388-4f2d-9cef-11ade88ace96'],
|
||||
['test.andreaslop.nl', '7fb301ab-6ecc-4aea-beee-71bcb6009bfe'],
|
||||
])('telt op %s met de juiste website', (hostname, websiteId) => {
|
||||
render(<UmamiAnalytics hostname={hostname} />);
|
||||
|
||||
const [script] = umamiScripts();
|
||||
expect(script.defer).toBe(true);
|
||||
expect(script.dataset).toMatchObject({
|
||||
websiteId,
|
||||
domains: hostname,
|
||||
doNotTrack: 'true',
|
||||
});
|
||||
});
|
||||
|
||||
it('voegt het script maar één keer toe', () => {
|
||||
render(<UmamiAnalytics hostname="andreaslop.nl" />);
|
||||
render(<UmamiAnalytics hostname="andreaslop.nl" />);
|
||||
expect(umamiScripts()).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('rendert niets zichtbaars', () => {
|
||||
const { container } = render(
|
||||
<UmamiAnalytics hostname="andreaslop.nl" />,
|
||||
);
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { SkipNavContent, SkipNavLink } from '@chakra-ui/react';
|
||||
import { Outlet } from '@tanstack/react-router';
|
||||
import siteContent from '@/content/siteContent';
|
||||
import useRouteFocus from '@/hooks/useRouteFocus';
|
||||
import UmamiAnalytics from './Analytics/UmamiAnalytics';
|
||||
import BackToTop from './BackToTop/BackToTop';
|
||||
import Footer from './Footer/Footer';
|
||||
import NavigationBar from './NavigationBar/NavigationBar';
|
||||
@@ -22,6 +23,7 @@ export default function AppShell() {
|
||||
</SkipNavContent>
|
||||
<Footer content={siteContent} />
|
||||
<BackToTop />
|
||||
<UmamiAnalytics />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import { useEffect } from 'react';
|
||||
import { chakra, useRecipe } from '@chakra-ui/react';
|
||||
import { useRouter, type ErrorComponentProps } from '@tanstack/react-router';
|
||||
import { reportError } from '@/monitoring/sentry';
|
||||
import LinkButton from '../LinkButton';
|
||||
import StatusPage from './StatusPage';
|
||||
|
||||
// Algemene foutpagina (FR-10). Toont nooit de foutmelding zelf; die gaat
|
||||
// alleen naar de console (BR-ERR-02/03).
|
||||
// alleen naar de console en Sentry (BR-ERR-02/03).
|
||||
export default function ErrorPage({ error, reset }: ErrorComponentProps) {
|
||||
const router = useRouter();
|
||||
const buttonRecipe = useRecipe({ key: 'linkButton' });
|
||||
|
||||
useEffect(() => {
|
||||
console.error(error);
|
||||
reportError(error);
|
||||
}, [error]);
|
||||
|
||||
// Foutgrens resetten en de route opnieuw laden (BR-ERR-04)
|
||||
|
||||
Reference in New Issue
Block a user