Lately, the Courts decided that you need to give your users the option to opt-in for every third-party service you are using. A lot of our clients were asking about a popup like this. Unfortunately, the famous Spatie package we used on most of our Sites is not addressing this. That was the point where we decided to write our own EU Cookie Consent package.
Our Goals have been to give users the option to opt-in per service and the developers to check if the user gave permission. As a small goodie, we implemented also an easy way to play out the allowed scripts to your page.
Installation:
You can install the package via composer:
composer require the42coders/eu-cookie-consent
Customize the popup:
Most of the customization can be done through the config file. First, you need to publish it.
The config file has a lot of comments to help you get started.
The core of the popup is defined in the cookies array. Here you can define the categories and inside of the categories the cookies. Categories are meant to organize the cookie permissions to topics. But feel free to just use one if it fits you. Every parameter in the array which is marked with Optional: in the comment above is optional :). Let's assume you want to add a Facebook cookie permission to the popup.
This is how the cookies part is looking at the moment.
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',
],
],
Now we add facebook permission to it.
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',
],
'facebook' => [],
],
Since this Package has multi-language support all the texts are set in the language files. To make changes we need to publish them first.
In the language file, you just need to add a new key and the content.
'facebook' => 'We want facebook to know everything about you. Please let us :).',
That's it! You added new cookie permission to the popup. You can also delete the already existing ones if you don't need them.
Use the Popup:
Now you want to show the popup on your Laravel site. We recommend to integrate it into your base blade file like the app.blade.php. This will render the Popup HTML and that is all you need.
{!! EuCookieConsent::getPopup() !!}
Check for Permissions:
But now you want to integrate the Facebook connection based on the permission of the user. The package gives you two ways to do so. 1. Check for permission in your blade file.
You can define any non taken key here as you will see later. You just need to use the same on all the cookie permissions you want to render at the same place. In your blade File, you can do this.
This will collect the header tag from all the cookie permissions the user allowed you to use and just output them here. If you want to have one part in the header and one in the footer you can just define both in the config array.
You made it!
Your page is now cookie GDPR compliant. If you have any ideas for improvements to this package feel free to contact us.