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
Requires
- php: >=8.4
- doctrine/orm: ^3.6
- psr/log: ^3.0
- symfony/asset-mapper: ^8.0
- symfony/config: ^8.0
- symfony/console: ^8.0
- symfony/dependency-injection: ^8.0
- symfony/framework-bundle: ^8.0
- symfony/http-foundation: ^8.0
- symfony/http-kernel: ^8.0
- symfony/security-csrf: ^8.0
- symfony/security-http: ^8.0
- symfony/stimulus-bundle: ^2.0
- symfony/twig-bundle: ^8.0
- symfony/ux-twig-component: ^2.0
Requires (Dev)
- doctrine/dbal: ^4.0
- phpstan/phpstan: ^1.11
- symfony/browser-kit: ^8.0
- symfony/phpunit-bridge: ^7.1
- symfony/security-bundle: ^8.0
Suggests
- doctrine/dbal: For database-backed consent storage (DBAL adapter)
- symfony/security-bundle: Optional: enables user-based audit logging via the security token storage
README
A Symfony 8 bundle for GDPR-compliant cookie consent with Twig integration, Stimulus.js, and flexible storage backends.
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.