https://github.com/weble/laravel-filament-cookiebar
GDPR compliant Cookiebar integrated with Google Tag Manager Consent Mode v2 for Laravel using Filament and Livewire
https://github.com/weble/laravel-filament-cookiebar
Last synced: about 1 year ago
JSON representation
GDPR compliant Cookiebar integrated with Google Tag Manager Consent Mode v2 for Laravel using Filament and Livewire
- Host: GitHub
- URL: https://github.com/weble/laravel-filament-cookiebar
- Owner: Weble
- License: mit
- Archived: true
- Created: 2024-01-16T10:14:35.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-10T04:28:58.000Z (over 1 year ago)
- Last Synced: 2025-05-17T00:15:23.475Z (about 1 year ago)
- Language: PHP
- Size: 711 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Laravel Filament CookieBar - GDPR and GTM friendly
[](https://packagist.org/packages/weble/laravel-filament-cookiebar)
[](https://github.com/weble/laravel-filament-cookiebar/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://packagist.org/packages/weble/laravel-filament-cookiebar)
GDPR compliant Cookiebar integrated with Google Tag Manager Consent Mode v2 for Laravel using Filament and Livewire
## Installation
You can install the package via composer:
```bash
composer require weble/laravel-filament-cookiebar
```
You can publish and run the migrations with:
```bash
php artisan vendor:publish --tag="cookiebar-migrations"
php artisan migrate
```
You can publish the config file with:
```bash
php artisan vendor:publish --tag="cookiebar-config"
```
Optionally, you can publish the language files using
```bash
php artisan vendor:publish --tag=cookiebar-lang"
```
This is the contents of the published config file:
```php
env('COOKIE_CONSENT_ENABLED', true),
/*
* The name of the cookie in which we store if the user
* has agreed to accept the conditions.
*/
'cookie_name' => '_cookieConsents',
/*
* Set the cookie duration in days. Default is 365 days.
*/
'cookie_lifetime' => 365,
/**
* Route / url to the terms page
*/
'terms_url' => '#',
/*
* Consents
* The key is the one used by GTM Consent Mode
*/
'consent_groups' => [
'required' => [
'title' => 'cookiebar::consents.required.label',
'description' => 'cookiebar::consents.required.description',
'consents' => [
GTMConsent::SECURITY_STORAGE,
GTMConsent::FUNCTIONALITY_STORAGE,
],
'disabled' => true,
'default' => true,
],
'analytics' => [
'title' => 'cookiebar::consents.analytics.label',
'description' => 'cookiebar::consents.analytics.description',
'consents' => [
GTMConsent::ANALYTICS_STORAGE,
GTMConsent::PERSONALIZATION_STORAGE,
],
'disabled' => false,
'default' => false,
],
'marketing' => [
'title' => 'cookiebar::consents.marketing.label',
'description' => 'cookiebar::consents.marketing.description',
'consents' => [
GTMConsent::AD_STORAGE,
GTMConsent::AD_PERSONALIZATION,
GTMConsent::AD_USER_DATA,
],
'disabled' => false,
'default' => false,
],
],
];
```
## Usage
This package relies and depends on the awesome [Spatie Google Tag Manager](https://github.com/spatie/laravel-googletagmanager) package.
To integrate with Google Tag Manager's consent mode v2 (which is encouraged) you should configure this package first, and then proceed into integrating the CookieBar.
### Basic Example
First you'll need to include both the default GTM Consent Mode setup and GTM scripts into your head and body tags:
```html
{{-- layout.blade.php --}}
@include('cookiebar::head')
{{-- ... --}}
@include('googletagmanager::body')
{{-- ... --}}
```
The `cookiebar::head` layout already includes spatie's GTM code for the head, so don't include both theirs script and ours.
You can then place the Cookiebar livewire component anywhere you like, and you're done,
```html
{{-- layout.blade.php --}}
@include('cookiebar::head')
{{-- ... --}}
@include('googletagmanager::body')
{{-- ... --}}
```
If you are in a Livewire full page component, or prefer having more control over what happens in the livewire component itself, you can use your own Livewire component and use the `HasCookieBar` trait to include all the functionalities you need
```php
{{ $slot ?? '' }}
@if($showCookieBar)
{{ $this->showCookieModalAction }}
{{ $this->agreeAction }}
{{ $this->dismissAction }}
@endif
```
The component will deal with creating the default consent status and sending the correct update events to GTM once the user accepts the cookies.
## Testing
```bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [Daniele Rosario](https://github.com/Skullbock)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.