Cookie Consent Management¶
The Zer0-Mistakes theme includes a GDPR/CCPA compliant cookie consent system with granular permission controls.

When the site configures a tracker (see When the Banner Appears), the banner appears until a visitor makes a choice; "Manage Cookies" opens a modal for granular analytics/marketing toggles. Consent gates analytics loading, so nothing tracks until the visitor opts in.
Overview¶
The cookie consent system provides:
- Privacy Compliance: GDPR and CCPA compliant
- Granular Controls: Per-category consent options
- Persistent Storage: 365-day consent persistence
- Bootstrap Integration: Native modal UI
Quick Start¶
When the Banner Appears¶
The banner, its "Manage Cookies" modal and the footer "Cookie Preferences" button render only when the site configures something that needs consent. Asking visitors to consent to cookies the site never sets would be misleading, so a site with no tracker shows none of them. The theme detects:
google_analyticsset to a measurement IDgoogle_tag_managerset to a container IDposthog.enabled: true
Override the detection with cookie_consent.enabled in _config.yml:
cookie_consent:
# enabled: true # force the banner on (e.g. trackers loaded via _includes/custom/ hooks)
# enabled: false # never render it, even with trackers configured
Leave enabled unset for automatic detection.
How It Works¶
Consent Flow¶
graph TD
A[User Visits Site] --> B{Has Consent?}
B -->|No| C[Show Banner]
B -->|Yes| D[Load Allowed Scripts]
C --> E[User Chooses]
E --> F[Store Preferences]
F --> D
Cookie Categories¶
| Category | Purpose | Required |
|---|---|---|
necessary |
Essential functionality | Yes |
analytics |
Usage tracking (PostHog, GA) | No |
marketing |
Advertising, tracking | No |
preferences |
User settings | No |
Configuration¶
Basic Setup¶
cookie_consent:
enabled: true # optional: unset = shown only when a tracker is configured
position: bottom # bottom, top
theme: light # light, dark, auto
expires: 365 # days
Category Configuration¶
cookie_consent:
categories:
necessary:
name: "Essential"
description: "Required for the website to function"
required: true
analytics:
name: "Analytics"
description: "Help us understand how you use our site"
required: false
default: false
Integration with Analytics¶
# PostHog and Google Analytics load only after the visitor accepts analytics
posthog:
enabled: true
privacy:
require_consent: true
google_analytics: G-XXXXXXXXXX
# GA follows posthog.privacy.require_consent; set this to override it for GA alone
# google_analytics_require_consent: true
Before a choice is made nothing is requested from PostHog or Google and no analytics cookie is set. Accept All (or saving preferences with Analytics on) loads both on the spot, without a reload; Reject All keeps them off.
Banner Customization¶
Text Content¶
cookie_consent:
text:
message: "We use cookies to improve your experience."
accept: "Accept All"
decline: "Decline"
settings: "Cookie Settings"
save: "Save Preferences"
Styling¶
Override styles in your CSS:
/* Custom banner styling */
.cookie-consent-banner {
background: var(--bs-dark);
color: var(--bs-light);
}
.cookie-consent-btn {
border-radius: var(--bs-border-radius);
}
JavaScript API¶
Check Consent¶
// Check if category is consented
if (CookieConsent.hasConsent('analytics')) {
// Load analytics
}
// Get all consents
const consents = CookieConsent.getConsents();
Listen for Changes¶
document.addEventListener('cookieConsent:update', function(e) {
const { category, consented } = e.detail;
console.log(`${category}: ${consented}`);
});
Programmatic Control¶
// Show settings modal
CookieConsent.showSettings();
// Revoke all consent
CookieConsent.revokeAll();
// Grant specific category
CookieConsent.grant('analytics');
Privacy Policy Integration¶
Link your privacy policy:
The consent banner will include a link to your privacy policy.
Compliance Features¶
GDPR Requirements¶
- ✅ Prior consent before non-essential cookies
- ✅ Granular category choices
- ✅ Easy withdrawal of consent
- ✅ Clear privacy information
- ✅ No pre-checked boxes
CCPA Requirements¶
- ✅ "Do Not Sell" option
- ✅ Privacy notice link
- ✅ Opt-out mechanism
- ✅ Record of consent
Best Practices¶
Essential Cookies Only¶
Never require consent for:
- Session cookies
- Authentication tokens
- CSRF protection
- Load balancing
Clear Descriptions¶
categories:
analytics:
description: |
We use analytics cookies to understand how you use our site.
This helps us improve your experience. We use PostHog, which
is privacy-focused and GDPR compliant.
Regular Audits¶
- Review cookie usage quarterly
- Update category descriptions
- Test consent flow
- Verify script blocking
Troubleshooting¶
Banner Not Showing¶
- Check that a tracker is configured (
google_analytics,google_tag_managerorposthog.enabled: true), or force it withcookie_consent.enabled: true;cookie_consent.enabled: falsehides it - Clear browser cookies
- Verify
components/cookie-consent.htmlis not overridden or removed from_layouts/root.html, which renders it behind thecomponents/cookie-consent-needed.htmlgate
Scripts Loading Without Consent¶
- Wrap scripts in consent checks
- Use conditional includes
- Verify category requirements
Consent Not Persisting¶
- Check cookie expiration
- Verify localStorage access
- Test in private browsing