All sites owned by EU citizens or targeted towards EU citizens must comply with a crazy EU law. This law requires a dialog to be displayed to inform the users of your websites how cookies are being used. You can read more info on the legislation on the site of the European Commission.
This package provides an easily configurable view to display the message. Also included is JavaScript code to set a cookie when a user agrees with the cookie policy. The package will not display the dialog when that cookie has been set.
You can install the package via composer:
composer require the42coders/eu-cookie-consent
Optionally you can publish the following Files
This is recommended since you can configure all the consents you want to get from the visitor.
php artisan vendor:publish --provider="the42coders\EuCookieConsent\EuCookieConsentServiceProvider" --tag="config"
If you want to customize the look and feel of the Package
php artisan vendor:publish --provider="the42coders\EuCookieConsent\EuCookieConsentServiceProvider" --tag="views"
This package comes with multilanguage support out of the box. You can translate it to the Languages you want. Or just change the default Text.
php artisan vendor:publish --provider="the42coders\EuCookieConsent\EuCookieConsentServiceProvider" --tag="lang"
This is the heart of the Package you can define all the Cookies/Permissions you want to get form the User.
return [
/*
* Use this setting to enable the cookie consent dialog.
*/
'enabled' => 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' => 'laravel_eu_cookie_consent',
/*
* Set the cookie duration in minutes. Default is 365 * 24 * 60 = 1 Year.
*/
'cookie_lifetime' => 365 * 24 * 60,
/*
* Multilanguage support
*
* If enabled the title, description, the category keys and the cookie keys are defining the key from the translation files.
*/
'multilanguage_support' => true,
/*
* Save Cookies Route
*/
'route' => '/saveTheCookie',
/*
* Define the style of the Popup
*/
'popup_style' => '',
/*
* Define classes the popup should use.
*/
'popup_classes' => 'eu-popup',
/*
* If you want to have an Accept all Button for the users
*/
'acceptAllButton' => 'true',
/*
* Cookies
*/
'cookies' => [
//Defines the translation Key for the saveButton
'saveButton' => 'Save',
//Optional: Defines the translation Key for the PopupTitle
'title' => 'PopupTitle',
//Optional: Defines the translation Key for the PopupDescription
'description' => 'PopupDescription',
//To make the popup easier to consume for the user you can organize your Cookies in categories.
'categories' => [
//The key defines the translation key in the translations for this category.
'essential' => [
//Optional: The description defines the key in the translations for the category description
'description' => 'essential_description',
//In this array you can define all the Cookies you want to request form the User
'cookies' => [
//The key defines the key in the translations and is used to access the Cookie specific information
'session' => [
//Optional: you can set forced to make it impossible for the user to not accept this cookie.
'forced' => 'true',
//Optional: The description defines the key in the translations
//'description' => 'key in translation File'
],
'xsrf-token' => [
'forced' => 'true',
],
],
],
],
],
];
To enable the Popup you can use the following Code in your blade Files (it returns html code).
{!! EuCookieConsent::getPopup() !!}
If you want to give the users the option to change the permissions just add another line
{!! EuCookieConsent::getUpdatePopup() !!}
This gives you the possibility to call the dialog with the given user settings by javascript.
Just call the following js function and the popup will appear.
update_popup()
If you want to check if the user gave you a specific permission. You can just pass the key of the Cookie you defined in the config file.
EuCookieConsent::canIUse('key from the cookies config')
Very often we want to play out a specific Script Tag ... only if the user allowed us. You can define the Scripts in the config of the cookie. If you use the key header for example you can render them from all of the cookies.
{!! EuCookieConsent::getHtml('header') !!}
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.