From 33dab93c8efe764acb68f3b759c5f7271029470a Mon Sep 17 00:00:00 2001 From: Rajpreet0 Date: Fri, 25 Sep 2026 19:35:58 +0200 Subject: [PATCH] see comments --- app/(legal)/datenschutz/page.tsx | 4 +-- .../shared/ui/components/cookie-consent.tsx | 36 ++++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/app/(legal)/datenschutz/page.tsx b/app/(legal)/datenschutz/page.tsx index e363382..673e6c0 100644 --- a/app/(legal)/datenschutz/page.tsx +++ b/app/(legal)/datenschutz/page.tsx @@ -376,9 +376,7 @@ const Datenschutz = () => {

Vercel Analytics

Wir nutzen auf unserer Website die Analysedienste Vercel Analytics der Vercel Inc. (440 Barranca Ave #4133, Covina, CA 91723, USA). - Diese Dienste dienen der Messung der Performance unserer Website (z. B. Ladezeiten) sowie der statistischen Auswertung - der Nutzung unseres Online-Angebots. Dabei werden technische Informationen (z. B. aufgerufene Seite, Browsertyp, Ladezeiten) - an Server von Vercel übermittelt. + Dabei werden technische Informationen (z. B. aufgerufene Seite, Browsertyp, Ladezeiten) an Server von Vercel übermittelt.

Die Einbindung und Verarbeitung erfolgt ausschließlich auf Grundlage Ihrer ausdrücklichen Einwilligung gemäß diff --git a/modules/shared/ui/components/cookie-consent.tsx b/modules/shared/ui/components/cookie-consent.tsx index 84c834b..0939c53 100644 --- a/modules/shared/ui/components/cookie-consent.tsx +++ b/modules/shared/ui/components/cookie-consent.tsx @@ -1,13 +1,20 @@ "use client"; import { Analytics } from "@vercel/analytics/next"; +import type { BeforeSendEvent } from "@vercel/analytics"; import * as CookieConsent from 'vanilla-cookieconsent'; import 'vanilla-cookieconsent/dist/cookieconsent.css'; -import { useEffect, useState } from "react"; +import { useEffect } from "react"; + +// Re-checked on every single event, so it stays correct for the rest of the +// session regardless of the component's own mount state. +// Module-level (not created inside the component) so its reference is +// stable across renders and Analytics doesn't re-register it needlessly. +function gateByConsent(event: BeforeSendEvent) { + return CookieConsent.acceptedCategory('analytics') ? event : null; +} export default function CookieBanner() { - const [analyticsAccepted, setAnalyticsAccepted] = useState(false); - useEffect(() => { document.documentElement.classList.add('cc--elegant-black'); @@ -28,11 +35,13 @@ export default function CookieBanner() { description: 'Diese Webseite nutzt optionale Cookies für Statistik und Marketing. Mehr dazu in unserer Datenschutzerklärung.', acceptAllBtn: 'Alle akzeptieren', + acceptNecessaryBtn: 'Nur notwendige', showPreferencesBtn: 'Einstellungen verwalten', }, preferencesModal: { title: 'Cookie-Einstellungen', acceptAllBtn: 'Alle akzeptieren', + acceptNecessaryBtn: 'Nur notwendige', savePreferencesBtn: 'Auswahl speichern', sections: [ { title: "Statistik", linkedCategory: 'analytics' } @@ -41,20 +50,21 @@ export default function CookieBanner() { }, }, }, - onConsent: ({ cookie }) => { - setAnalyticsAccepted(cookie.categories.includes('analytics')); - }, - onChange: ({ cookie }) => { - setAnalyticsAccepted(cookie.categories.includes('analytics')) - } }) }, []); - if (!analyticsAccepted) return null; - return ( <> - + {/* + * Always mounted, regardless of consent: @vercel/analytics injects + * its script into on mount and never removes it on unmount + * (v2.0.1 has no cleanup), so a script that already loaded would + * keep tracking after consent is withdrawn if we unmounted this. + * Gating happens per-event in beforeSend instead, which is + * re-checked live on every event and therefore stays effective + * for the rest of the session, including after withdrawal. + */} + ) -} \ No newline at end of file +}