Skip to content

Cookie Consent Management

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

The site with the cookie-consent banner pinned along the bottom — "We value your privacy" with Manage Cookies, Reject All, and Accept All actions

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_analytics set to a measurement ID
  • google_tag_manager set to a container ID
  • posthog.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

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
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.

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 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:

cookie_consent:
  privacy_policy: /privacy-policy/
  show_policy_link: true

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

  1. Review cookie usage quarterly
  2. Update category descriptions
  3. Test consent flow
  4. Verify script blocking

Troubleshooting

  1. Check that a tracker is configured (google_analytics, google_tag_manager or posthog.enabled: true), or force it with cookie_consent.enabled: true; cookie_consent.enabled: false hides it
  2. Clear browser cookies
  3. Verify components/cookie-consent.html is not overridden or removed from _layouts/root.html, which renders it behind the components/cookie-consent-needed.html gate
  1. Wrap scripts in consent checks
  2. Use conditional includes
  3. Verify category requirements
  1. Check cookie expiration
  2. Verify localStorage access
  3. Test in private browsing

See also