/cookies-popup

Cookie consent management for Laravel projects

Primary LanguagePHPMIT LicenseMIT

Cookies popup

Laravel package

This package provides a popup layer to manage cookies consent

Latest Version on Packagist Total Downloads

Installation

You can install the package via composer:

composer require itemvirtual/cookies-popup

Publish config file (with --force option to update)

php artisan vendor:publish --provider="Itemvirtual\CookiesPopup\CookiesPopupServiceProvider" --tag=config

You need to add package cookies to the EncryptCookies except array

# file app/Http/Middleware/EncryptCookies.php
protected $except = [
    'analytical_cookies',
    'advertising_cookies',
    'recaptcha_cookies',
    'preferences_cookies',
];

Generate translations

There is a command to create the required translations in labels section

php artisan cookies-popup:generate-labels

If you prefer to create the translations in a file, these are the necessary indexes

cookies-popup-title
cookies-popup-text
cookies-popup-configure
cookies-popup-accept
accept-required-cookies-label
accept-required-cookies-info
accept-preferences-cookies-label
accept-preferences-cookies-info
accept-analytical-cookies-label
accept-analytical-cookies-info
accept-advertising-cookies-label
accept-advertising-cookies-info
accept-recaptcha-cookies-label
accept-recaptcha-cookies-info
cookies-popup-close

Usage

Print popup

To add cookie popup, put this code after footer in your html layout

{!! \Itemvirtual\CookiesPopup\CookiesPopup::addCookiesPopup() !!}

To add a link to open the cookie popup, use the id cookies-popup-show parameter

<a href="#" id="cookies-popup-show">Cookies</a>

Check if cookies are allowed

To hide or show content related with the cookies consent, use the allowed methods

@if(\Itemvirtual\CookiesPopup\CookiesPopup::allowedAnalyticalCookies())
@endif
@if(\Itemvirtual\CookiesPopup\CookiesPopup::allowedAdvertisingCookies())
@endif
@if(\Itemvirtual\CookiesPopup\CookiesPopup::allowedRecaptchaCookies())
@endif
@if(\Itemvirtual\CookiesPopup\CookiesPopup::allowedPreferencesCookies())
@endif

Add Google Analytics scripts

To add the scripts in your layout (gtag.js or analytics.js), use the method you need ()

{!! \Itemvirtual\CookiesPopup\CookiesPopup::getGtagJs() !!}
{!! \Itemvirtual\CookiesPopup\CookiesPopup::getAnalyticsJs() !!}

You need to add an env variable GA_MEASUREMENT_ID it can be a comma separated array

GA_MEASUREMENT_ID="UA-XXXXX-Y"
GA_MEASUREMENT_ID="UA-XXXXX-Y, AW-XXXXXXX"

The analytics.js script can be normal or async script more info

analytics.js
Universal Analytics (gtag.js)

Styling

To styling your pop-up window, you have two options.
The custom_styles or custom_classes config parameters.

With custom_styles you can change some CSS styles. If you need a deeper design change, use custom_classes, which will concatenate your class to the generic one

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.