Skip to content

feat(privacy): cookie consent banner — gate GTM behind user consent#49

Merged
fungc-io merged 1 commit intomainfrom
feat/cookie-consent
May 4, 2026
Merged

feat(privacy): cookie consent banner — gate GTM behind user consent#49
fungc-io merged 1 commit intomainfrom
feat/cookie-consent

Conversation

@chpapa
Copy link
Copy Markdown
Member

@chpapa chpapa commented May 1, 2026

Summary

  • Integrates vanilla-cookieconsent v3 (MIT, same stack as FormX.ai) to block GTM from loading until the visitor explicitly accepts analytics cookies
  • GTM bootstrap moved into a deferred window.__loadGtm() function — no tracking fires until consent is granted
  • Three consent categories: Necessary (always on), Analytics (GTM + _ga* auto-clear on rejection), Marketing (placeholder for future tags)
  • Bilingual banner (en + zh-Hant) with server-rendered strings via the existing t() i18n helper
  • "Cookie settings" button added to the footer bottom bar — reopens preferences at any time

close #50

Screenshots

Banner (en) — bottom-right box, no page interaction blocked:

We use cookies / Accept all / Reject all / Manage preferences / Privacy Policy

Preferences modal — per-category toggles with descriptions, Save preferences.

zh-Hant banner renders 我們使用 Cookie with correct Traditional Chinese copy throughout.

Test plan

  • Load / with PUBLIC_GTM_ID set → banner appears bottom-right, GTM network request absent
  • Click Reject allauthgear_cc cookie written with analytics:false, no GTM request
  • Click Accept all → GTM loads (gtm.js in network tab)
  • Toggle Analytics off in preferences → _ga* cookies cleared on save
  • Click "Cookie settings" in footer → preferences modal reopens
  • Load /zh-hant/ → banner copy renders in Traditional Chinese
  • npm run build → builds cleanly
  • Smoke test GTM assertion still passes (ID present in page source inside __loadGtm function)

🤖 Generated with Claude Code

Integrates vanilla-cookieconsent v3 (MIT, open-source) to block Google
Tag Manager from loading until the visitor explicitly accepts analytics
cookies — closing a GDPR/ePrivacy gap where GTM fired unconditionally.

- New CookieConsentBanner.astro component: server-renders i18n strings
  for both en and zh-Hant locales, initialises the banner bottom-right,
  and calls window.__loadGtm() on analytics consent
- BaseLayout.astro: GTM bootstrap moved into window.__loadGtm() deferred
  function; banner rendered whenever PUBLIC_GTM_ID is set
- SiteFooter.astro + navigation-data.ts: "Cookie settings" button in the
  bottom bar reopens the preferences modal via window.__cc.showPreferences()
- en.json + zh-Hant.json: CookieConsent namespace with full bilingual copy

Categories: necessary (always on), analytics (GTM/_ga* cookies),
marketing (placeholder for future tags). Auto-clears _ga* on rejection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@fungc-io fungc-io self-assigned this May 4, 2026
@fungc-io fungc-io self-requested a review May 4, 2026 09:26
Copy link
Copy Markdown
Contributor

@fungc-io fungc-io left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — cookie consent gating GTM behind opt-in, bilingual copy, footer reopener, no breaking changes.

@fungc-io fungc-io merged commit eb675b9 into main May 4, 2026
@fungc-io fungc-io deleted the feat/cookie-consent branch May 4, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Cookie-consent bar for required countries

2 participants