jostkleigrewe/cookie-consent-bundle

Symfony 8 bundle for GDPR-compliant cookie consent with Twig, Stimulus, and Turbo integration.

Installs: 4

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/jostkleigrewe/cookie-consent-bundle

v0.3.0 2026-01-26 21:30 UTC

This package is auto-updated.

Last update: 2026-01-27 17:43:35 UTC


README

Packagist Version PHP Version License

A Symfony 8 bundle for GDPR-compliant cookie consent with Twig integration, Stimulus.js, and flexible storage backends.

Deutsche Version

Features

  • ๐ŸŽฏ GDPR-Compliant - Cookie consent with policy versioning and audit logging
  • ๐ŸŽจ Multiple Themes - Tabler (light/dark), Bootstrap, or bring your own
  • โšก Stimulus.js - Turbo-friendly, no full page reload needed
  • ๐Ÿงญ Flexible Storage - Cookie, Doctrine, or both combined
  • ๐Ÿงฉ Vendor-Level Consent - Optional per-vendor toggles inside categories
  • ๐Ÿ›ก๏ธ Session Protection - Prevents session cookies without consent
  • ๐Ÿ“Š Google Consent Mode v2 - Built-in GA4 and Google Ads integration
  • ๐ŸŽฌ Embed Components - YouTube, Vimeo, Google Maps, and more with consent gates
  • ๐Ÿงช Twig Helpers - cookie_consent_has(), cookie_consent_modal(), and more

Requirements

  • PHP 8.4+
  • Symfony 8.0+
  • Twig Bundle, Security Bundle, Stimulus Bundle

Quick Start

1. Install

composer require jostkleigrewe/cookie-consent-bundle

2. Configure assets

// assets/app.js
import '@jostkleigrewe/cookie-consent-bundle/styles/cookie_consent.css';
// assets/controllers.json
{
  "controllers": {
    "@jostkleigrewe/cookie-consent-bundle": {
      "cookie-consent": { "enabled": true, "fetch": "eager" }
    }
  }
}

3. Render the modal

{# templates/base.html.twig #}
{{ cookie_consent_modal() }}

4. Gate content by consent

{% if cookie_consent_has('analytics') %}
  <script src="https://example.com/analytics.js"></script>
{% endif %}

Or use lazy loading:

<script type="text/plain" data-consent-category="analytics"
        data-consent-src="https://example.com/analytics.js"></script>

Configuration

Create config/packages/cookie_consent.yaml:

cookie_consent:
  policy_version: '1'
  storage: cookie  # cookie, doctrine, or both

  categories:
    necessary:
      label: Necessary
      required: true
      default: true
    analytics:
      label: Analytics
      default: false
    marketing:
      label: Marketing
      default: false
      vendors:
        google_ads:
          label: Google Ads
          default: false

  ui:
    template: '@CookieConsent/styles/tabler/modal.html.twig'
    position: center
    privacy_url: '/privacy'
    reload_on_change: false

  logging:
    retention_days: null

  google_consent_mode:
    enabled: false

If storage is set to doctrine or both, generate migrations in your app (bundle ships entities, not migrations). This requires Doctrine ORM:

bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate

Increment policy_version when changing categories to require re-consent.

Documentation

  • Getting Started - Installation, assets, first steps
  • Configuration - All options, templates, Twig helpers
  • Advanced - Storage backends, session enforcement, logging, events
  • Integration - Components, helpers, attributes, data attributes, events

Embed Components

Gate third-party content with built-in components:

<twig:CookieConsentYoutubeEmbed
  video_id="dQw4w9WgXcQ"
  category="marketing"
  vendor="youtube"
/>

Alternative:

{{ component('CookieConsentYoutubeEmbed', {
  video_id: 'dQw4w9WgXcQ',
  category: 'marketing',
  vendor: 'youtube'
}) }}

Available: YouTube, Vimeo, Google Maps, Spotify, Twitter/X, Instagram, TikTok, and more.

Integration Overview

See Integration for Twig components, helpers, data attributes, controller attributes, and events.

Contributing

composer install
composer ci

License

MIT - see LICENSE.

Resources