feat(privacy): consent-gated cookie banner (no tracking until accepted)#12
Merged
Conversation
Add a cookie consent banner shown on every page (content pages and the map) and stop loading Google Analytics until the visitor accepts. - lib/analytics: consent-aware layer. trackEvent holds events in an in-memory queue while consent is unknown (nothing leaves the browser); on accept the queue is flushed and later events fire live; on decline the queue is dropped and nothing is ever sent. Choice persisted in localStorage and restored for returning visitors. - CookieConsent: banner + consent-gated GoogleAnalytics loader. GA is only mounted after accept, so no tracking cookies/requests occur beforehand; once gtag is ready the queued events drain. Uses useSyncExternalStore so the server renders neither banner nor analytics. - Root layout renders the banner instead of GA unconditionally. - consent strings added for en/de/es/fr. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Was
Ein Cookie-Consent-Banner auf jeder Seite (Content-Seiten und Karte), plus korrektes Consent-Gating: bis akzeptiert wird nichts getrackt, danach werden vorher aufgelaufene Events nachgeliefert und ab dann live gefeuert.
Verhalten (genau wie gewünscht)
trackEvent-Aufrufe wandern in eine In-Memory-Queue — nichts verlässt den Browser.gtagbereit ist, wird die Queue geleert (Nachlieferung), und alle weiteren Events feuern live.localStorage; wiederkehrende Besucher sehen den Banner nicht erneut, akzeptierte laden GA sofort.Umsetzung
lib/analytics.ts— consent-aware Layer (Queue, Zustandunknown|granted|denied, Flush, Persistenz).trackEvent-Signatur unverändert, alle bestehenden Aufrufer (LanguageSwitcher, ContactForm, MapDisclaimer) profitieren automatisch.components/CookieConsent.tsx— Banner + consent-gatedGoogleAnalytics-Loader. NutztuseSyncExternalStore, damit der Server weder Banner noch Analytics rendert (kein Flash, keine Hydration-Mismatches). Polltgtag-Readiness und flusht dann die Queue.Verifikation
markGtagReady; Wiederherstellung auslocalStorage; Persistenz; Subscribe/Unsubscribe./,/destination/gothenburgund/mapenthalten keingoogletagmanagervor Consent.tsc✓,eslint✓ (0 errors),next build✓. 38 vorbestehendeReact.act-Testfehler unverändert, keine neuen.Hinweis: Einen Live-Klick-Durchlauf im Browser konnte ich in dieser Umgebung nicht ausführen (kein Browser-Tool verfügbar); die Consent-Logik ist aber durch Unit-Tests abgedeckt und das GA-Gating per SSR-Check bestätigt.
Generated with Claude Code