feat: add GDPR cookie consent banner (#1216)
* feat: add GDPR cookie consent banner
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
* refactor: move consent-gated GA to cookies/analytics.html
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.
* style: indent cookies/analytics.html
* refactor: don't use default, put default configurations in params.toml
* fix: don't use `description` as translation key because it's reserved and will throw error
* fix: remove footer/components/custom-font.html call
* fix: banner showSettings key
* style: indent comments/include
* Add missing article.alert translation back
* style: format i18n toml files
* style: indent head/head.html
* style adjustment
* style: add missing -
* style: format demo/config/params.toml
* style: remove redundant comments from cookies.scss
* style: update box-shadow for cookie banner content
---------
Co-authored-by: delize <4028612+delize@users.noreply.github.com>
Co-authored-by: Jimmy Cai <jimmy@cai.im>
This commit is contained in:
co-authored by
delize
Jimmy Cai
parent
3a0d70ebbd
commit
4ad88a327e
+29
-5
@@ -15,12 +15,12 @@ darkMode = "ডার্ক মোড"
|
||||
[article]
|
||||
back = "পেছনে"
|
||||
tableOfContents = "সূচিপত্র"
|
||||
relatedContent = "সম্পর্কিত বিষয়বস্তু"
|
||||
relatedContent = "সম্পর্কিত বিষয়বস্তু"
|
||||
lastUpdatedOn = "সর্বশেষ আপডেট করা হয়েছে"
|
||||
|
||||
[article.readingTime]
|
||||
one = "{{ .Count }} মিনিটে পড়া যাবে"
|
||||
other = "{{ .Count }} মিনিটে পড়া যাবে"
|
||||
one = "{{ .Count }} মিনিটে পড়া যাবে"
|
||||
other = "{{ .Count }} মিনিটে পড়া যাবে"
|
||||
|
||||
[article.alert]
|
||||
note = "টীকা"
|
||||
@@ -30,7 +30,7 @@ darkMode = "ডার্ক মোড"
|
||||
caution = "সাবধানতা"
|
||||
|
||||
[notFound]
|
||||
title = "পাওয়া যায়নি"
|
||||
title = "পাওয়া যায়নি"
|
||||
subtitle = "এই পাতাটি বিদ্যমান নেই"
|
||||
|
||||
[widget]
|
||||
@@ -50,5 +50,29 @@ darkMode = "ডার্ক মোড"
|
||||
resultTitle = "#PAGES_COUNT পাতা (#TIME_SECONDS সেকেন্ড)"
|
||||
|
||||
[footer]
|
||||
builtWith = "{{ .Generator }} দিয়ে নির্মিত"
|
||||
builtWith = "{{ .Generator }} দিয়ে নির্মিত"
|
||||
designedBy = "থিম {{ .Theme }} ডিজাইন করেছেন {{ .DesignedBy }}"
|
||||
|
||||
[cookies]
|
||||
title = "কুকি সম্মতি"
|
||||
text = "আমরা আপনার ব্রাউজিং অভিজ্ঞতা উন্নত করতে এবং সাইট ট্রাফিক বিশ্লেষণ করতে কুকি ব্যবহার করি।"
|
||||
acceptAll = "সবগুলো গ্রহণ করুন"
|
||||
deny = "প্রত্যাখ্যান"
|
||||
managePreferences = "পছন্দসমূহ পরিচালনা করুন"
|
||||
settingsTitle = "কুকি পছন্দসমূহ"
|
||||
savePreferences = "পছন্দসমূহ সংরক্ষণ করুন"
|
||||
cancel = "বাতিল"
|
||||
footerLink = "কুকি সেটিংস"
|
||||
commentsDisabled = "আপনি কার্যকরী কুকি গ্রহণ না করা পর্যন্ত মন্তব্য অক্ষম করা আছে।"
|
||||
|
||||
[cookies.necessary]
|
||||
title = "প্রয়োজনীয়"
|
||||
text = "এই কুকিগুলি ওয়েবসাইট কাজ করার জন্য প্রয়োজনীয় এবং নিষ্ক্রিয় করা যায় না।"
|
||||
|
||||
[cookies.analytics]
|
||||
title = "বিশ্লেষণ"
|
||||
text = "এই কুকিগুলি আমাদের বুঝতে সাহায্য করে যে দর্শকরা কীভাবে আমাদের ওয়েবসাইটের সাথে ইন্টারঅ্যাক্ট করে।"
|
||||
|
||||
[cookies.functional]
|
||||
title = "কার্যকরী"
|
||||
text = "এই কুকিগুলি মন্তব্য এবং এম্বেড করা বিষয়বস্তুর মতো বৈশিষ্ট্যগুলি সক্ষম করে."
|
||||
|
||||
Reference in New Issue
Block a user