Skip to content

Conversation

@delize
Copy link
Contributor

@delize delize commented Dec 24, 2025

Add a GDPR-compliant cookie consent banner that gates analytics (Google Analytics) and functional cookies (comments) until user consent is given.

Features:

  • Theme-consistent styling using CSS variables (light/dark mode)
  • Settings panel with category toggles (necessary, analytics, functional)
  • Consent stored in cookie for 365 days
  • Google Analytics only loads after analytics consent
  • Comments only load after functional consent
  • Translations for all 32 supported languages
  • Accessible with proper ARIA attributes and focus management

Configuration in hugo.yaml:
params: cookies: enabled: true categories: analytics: true functional: true

When cookies.enabled is false, scripts load normally without consent gating.

Closes #412

Add a GDPR-compliant cookie consent banner that gates analytics (Google
Analytics) and functional cookies (comments) until user consent is given.

Features:
- Theme-consistent styling using CSS variables (light/dark mode)
- Settings panel with category toggles (necessary, analytics, functional)
- Consent stored in cookie for 365 days
- Google Analytics only loads after analytics consent
- Comments only load after functional consent
- Translations for all 32 supported languages
- Accessible with proper ARIA attributes and focus management

Configuration in hugo.yaml:
  params:
    cookies:
      enabled: true
      categories:
        analytics: true
        functional: true

When cookies.enabled is false, scripts load normally without consent gating.

Closes CaiJimmy#412
@delize
Copy link
Contributor Author

delize commented Dec 24, 2025

I took note of the previous PR that was attempted with Cookie Consent, and you mentiond that it "wasn't fitting into the style".

This should match similar styling as much as possible. Some demos of it below (without having to visit the netlify site, you still can 😄 )

Banner (Dark Theme)

cookie-banner-dark-mode

Banner (Light Theme)

Screenshot 2025-12-24 at 16 43 30

Preferences (Dark Theme)

Screenshot 2025-12-24 at 16 44 42

Preferences (Light Theme)

Screenshot 2025-12-24 at 16 44 05

Functional Cookies Disabled - Comments Section (Dark Theme)

Screenshot 2025-12-24 at 16 45 27

Functional Cookies Disabled - Comments Section (Light Theme)

comments-consent-disabled-light

@delize delize marked this pull request as draft December 24, 2025 22:58
@delize delize marked this pull request as ready for review December 24, 2025 23:06
Move Google Analytics consent logic to avoid shadowing Hugo's internal
`_internal/google_analytics.html` template.

Changes:
- Rename google_analytics.html → cookies/analytics.html
- Update head.html to conditionally load:
  - cookies.enabled=true: cookies/analytics.html (consent-gated)
  - cookies.enabled=false: Hugo's _internal/google_analytics.html
- Align cookies/analytics.html with Hugo's internal template:
  - Support Privacy.GoogleAnalytics.Disable setting
  - Support Privacy.GoogleAnalytics.RespectDoNotTrack setting
  - Add UA- prefix deprecation warning

Note: Custom JS is required for consent-gated GA because Hugo templates
render at build time, but consent happens at runtime. We cannot call
Hugo's internal template after the user grants consent - we must
dynamically inject the GA script via JavaScript.
@delize delize force-pushed the GDPR-cookie-consent branch from 46d9727 to d16f29c Compare December 24, 2025 23:14
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.

feat: GDPR prompt

1 participant