Giter Club home page Giter Club logo

laravel-cookie-consent's Introduction

Card of Laravel Cookie consent

Laravel cookie consent modal

Latest Version on Packagist Total Downloads

Modal cookie consent

Preferences Modal

The package includes a script & styling for a cookie banner and a modal where the visitor can select his/her cookie preferences.

This package is mainly based on the one from spatie: https://github.com/spatie/laravel-cookie-consent

With the only exception that you can choose which cookies you enable. This only works when Google Tag Manager is correctly configured (some regex config based on the value set in the cookie).

Upgrading

You can find our upgrading guides here.

Installation

You can install the package via composer:

composer require statikbe/laravel-cookie-consent

The package will automatically register itself.

First of all you need to publish the javascript and css files:

php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="cookie-public"

Include the css/cookie-consent.css into your base.blade.php or any other base template you use.

<link rel="stylesheet" type="text/css" href="{{asset("vendor/cookie-consent/css/cookie-consent.css")}}">

The javascript file is included in the cookie snippet and will be added at the end of your body.

Usage

Instead of including a snippet in your view, we will automatically add it. This is done using middleware using two methods:

  1. The first option: include it in your entire project using the kernel:
// app/Http/Kernel.php

class Kernel extends HttpKernel
{
    protected $middleware = [
        // ...
        \Statikbe\CookieConsent\CookieConsentMiddleware::class,
    ];

    // ...
}
  1. The second option: include it as a route middleware and add this to any route you want.
// app/Http/Kernel.php

class Kernel extends HttpKernel
{
    // ...
    
    protected $routeMiddleware = [
        // ...
        'cookie-consent' => \Statikbe\CookieConsent\CookieConsentMiddleware::class,
    ];
}


// routes/web.php
Route::group([
    'middleware' => ['cookie-consent']
], function(){
    // ...
});

This will add cookieConsent::index to the content of your response right before the closing body tag.

Customising the dialog texts

If you want to modify the text shown in the dialog you can publish the lang-files with this command:

php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="cookie-lang"

This will publish this file to resources/lang/vendor/cookieConsent/en/texts.php.

return [
    'alert_title' => 'Deze website gebruikt cookies',
    'setting_analytics' => 'Analytische cookies',
];

If you want to translate the values to, for example, English, just copy that file over to resources/lang/vendor/cookieConsent/fr/texts.php and fill in the English translations.

Customising the dialog contents

If you need full control over the contents of the dialog. You can publish the views of the package:

php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="cookie-views"

This will copy the index view file over to resources/views/vendor/cookieConsent.

The cookie-settings view file is just a snippet you need to place somewhere onto your page. Most preferably in the footer next to the url of your cookie policy.

<a href="javascript:void(0)" class="js-lcc-settings-toggle">@lang('cookie-consent::texts.alert_settings')</a>

This gives your visitor the opportunity to change the settings again.

Publishing

Config

php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="cookie-config"

This is the contents of the published config-file: This will read the policy urls from your env.

return [
    'cookie_key' => '__cookie_consent',
    'cookie_value_analytics' => '2',
    'cookie_value_marketing' => '3',
    'cookie_value_both' => 'true',
    'cookie_value_none' => 'false',
    'cookie_expiration_days' => '365',
    'gtm_event' => 'pageview',
    'ignored_paths' => [],
    'policy_url_en' => env('COOKIE_POLICY_URL_EN', null),
    'policy_url_fr' => env('COOKIE_POLICY_URL_FR', null),
    'policy_url_nl' => env('COOKIE_POLICY_URL_NL', null),
];

You can customize some settings that work with your GTM.

Don't show modal on cookie policy page or other pages

If you don't want the modal to be shown on certain pages you can add the relative url to the ignored paths setting. This also accepts wildcards (see the Laravel Str::is() helper).

'ignored_paths => ['/en/cookie-policy', '/api/documentation*'];

Translations

php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="cookie-lang"

Views

php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="cookie-views"

Configure Google Tag Manager

All the steps to configure your Google Tag Manager can be found here.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

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

laravel-cookie-consent's People

Contributors

borjajimnz avatar carolineboeykens avatar dduupp avatar dependabot[bot] avatar janhenckens avatar javiersanzsanchez avatar kobo-one avatar kristofser avatar mejans avatar stijnelskens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-cookie-consent's Issues

Allow navigation with essential cookies

Hi,

is it possible to allow website navigation with essential cookies and show banner on every page until the user takes a decision?
I have installed the package and banner shows right but all buttons, menu etc.. on the page is disabled.
I have seen "inert" is added to DOM elements but don't know how to disable that and if there's an option.

No hint path defined for [cookie-consent].

I have installed this. working on my local fine. but getting error 'No hint path defined for [cookie-consent].' on server.
I added this in app/Http/Kerne.php to include it in my entire project: \Statikbe\CookieConsent\CookieConsentMiddleware::class

Unable to remove this package

I removed this package from my project

Now composer cannot more do dump autoload

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   TypeError

  Argument 2 passed to Illuminate\View\Factory::__construct() must be an instance of Illuminate\View\ViewFinderInterface, null given, called in C:\laragon\www\<project name redacted>\vendor\laravel\framework\src\Illuminate\View\ViewServiceProvider.php on line 65

  at C:\laragon\www\<project name redacted>\vendor\laravel\framework\src\Illuminate\View\Factory.php:101
     97▕      * @param  \Illuminate\View\ViewFinderInterface  $finder
     98▕      * @param  \Illuminate\Contracts\Events\Dispatcher  $events
     99▕      * @return void
    100▕      */
  ➜ 101▕     public function __construct(EngineResolver $engines, ViewFinderInterface $finder, Dispatcher $events)
    102▕     {
    103▕         $this->finder = $finder;
    104▕         $this->events = $events;
    105▕         $this->engines = $engines;

  1   C:\laragon\www\<project name redacted>\vendor\laravel\framework\src\Illuminate\View\ViewServiceProvider.php:65
      Illuminate\View\Factory::__construct(Object(Illuminate\View\Engines\EngineResolver), Object(Illuminate\Events\Dispatcher))

  2   C:\laragon\www\<project name redacted>\vendor\laravel\framework\src\Illuminate\View\ViewServiceProvider.php:42
      Illuminate\View\ViewServiceProvider::createFactory(Object(Illuminate\View\Engines\EngineResolver), Object(Illuminate\Events\Dispatcher))
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

What damn is this error?!

I rechecked 123 times, my project doesn't include any reference to provider or what else of this package. I deleted middlewares and removed from appserviceprovider, i removed app/config/ specific file... I removed all views and ensured i do not include these views anymore.

I also did a rm -rf vendor and a composer clear-cache. I manually deleted all caches of laravel app, from storage/framework and from /bootstrap/cache ... I deleted also composer.lock before retry a composer update

What damn is this error?

The absurd is that if I readd the package, the error disappear. What else should I search in my project!?!?

Can't understand step 3 of "How to configure Google Tag Manager"

I started to follow the "How to configure Google Tag Manager" documentation.
I can't understand which GTM screen the step 3 is related to.

The title "Universal Analytics" that I can see in the screenshot is confusing me.
It is not mentioned in the previous steps.
Where does it come from?

After step 2, when I click the "tag" tab as asked in step 3, I can't see anything looking like in the screenshot.

Also, in the screenshot provided in step 3, I can see that the type of "GDPR - Has not given censent" trigger is "Page View".
But in step 2 we created a "GDPR - Has not given censent" trigger of type "Custom Event".
Did I miss something?

By the way, thank you very much for this documentation which seems great!

Cookies still present after withdrawing consent

I have implemented the package with GTM for my site but I think I might have a problem in the scenario where a user accepts all cookies but then changes their mind using the adjust preferences link.

Reproduction steps:

  1. Load the website and observe the cookie pop up and only essential cookies are set (using Chrome Dev Tools)
  2. Click 'accept all cookies'. Observe the cookie pop up closes and GA cookies are also set
  3. In the footer of the site, click 'adjust your preferences' and untick analytical and marketing cookies. Click 'save my selection'.

Actual behavior:
GA cookies remain and are still set

Expected behavior:
GA cookies are removed and only essential cookies are set

Is this expected or a bug?

I have re-checked that I followed all of the GTM steps as per the documentation:
image

GTM Configuration Issue

Hi, I have followed the steps in GTM configuration provided here (https://github.com/statikbe/laravel-cookie-consent/blob/master/docs/google-tag-manager.md). But I am not sure of two things:

  1. In the screenshot, there is no showing that the GDPR - Consent for marketing cookies trigger should be added but it was mentioned in Step 7. So, which way is correct?
  2. I faced this error when trying to publish the changes -->
    Invalid “Google Analytics Settings” field | Google Analytics | Incompatible variable reference “Event” found in this tag. Please either revert your changes or update the “Google Analytics Settings” field in the tag.

Any help will be appreciated.

Modals don't show up

Environment:

Local website / Laravel 6.18.25 / PHP 7.4 / jQuery 3.1.1

Steps to reproduce:

Package (1.2.0) installed via composer:

composer require statikbe/laravel-cookie-consent

Javascript and css files publication:

php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="public"

Added both css/cookie-consent.css & js/cookie-consent.js in the base template file, and web page source code checked for correct files insertion:

    <link rel="stylesheet" type="text/css" href="{{asset('vendor/cookie-consent/css/cookie-consent.css')}}">
    ...
    <script src="{{asset('vendor/cookie-consent/js/cookie-consent.js')}}"></script>

Added Statikbe\CookieConsent\CookieConsentMiddleware to app/Http/Kernel.php:

class Kernel extends HttpKernel
{
    protected $middleware = [
        // ...
        \Statikbe\CookieConsent\CookieConsentMiddleware::class,
    ];

    // ...
}

No translation configured ("Customising the dialog texts" and "Customising the dialog contents" steps from the README not used).

cookie-settings snippet placed in the footer, with a hard-coded label:

<a href="#" class="js-lcc-modal-alert">Cookies preferences</a>

Configuration published:

php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="config"

Cache cleared:

php artisan cache:clear
php artisan view:clear

And that's all.

Issue observed:

Going to the homepage of the website, I only see the grey transparent .lcc-backdrop div.
The two other div (lcc-modal--alert & lcc-modal--settings) are not visible (display: none).
Checking the "__cookie_consent" cookie status: not present.

Reproduced on Chrome, Firefox & Edge.

Notes:

  • In fact it did work once: I have seen both modals (on Chrome) the very first time I accessed the website after having installed the package.
  • No Javascript error displayed in the console.
  • No error display in the Laravel debugbar.
  • No parameter changed in cookie-consent.php.
  • Whole process repeated twice with the same result.

No page refresh after cookie consent given?

[Package version: 1.2.1]

I expected the page to be refreshed after cookie consent, but it's not the behavior I observe in my case.

Is not the page supposed to be refreshed when the user gives consent, to immediately take this setting into account?

How recall modal with a simple link ?

The user has just validated the modal window of the cookies. He made a mistake and would like to return to it. What is the code or the function that allows to do it in blade (href ?)
Thank

Unexpected parenthesis in the Cookie settings pop-up

[Package version: 1.2.1]

In the French version of the Cookie settings pop-up, the first paragraph ends with an unexpected closing parenthesis (see attached image).
This character is not present in the French translation of this sentence.

I can't figure out where this parenthesis comes from.

unexpected_parenthesis

Ability to reject all?

In a few GDPR countries you have to provide a button to Reject All in addition to Accept all, I wanted to customize this myself but I'm not sure it's possible without touching the code itself, could this be a possible feature to be added?

Consent mode v2

Is there a way II can use this to comply this with new Consent mode v2 ?

ignored_paths

I don't want the modal to be shown on certain pages, so I must add the route to ignored_paths array in the config file. For a route as 'admin/users' every thing is fine but for a route as 'admin/user/{id}' it doesn't work. How can I fix it or how can say all the routes which start with '/admin' don't show the cookie policy?

Modal doesn't open - Bootstrap conflict?

I have installed the package as per the docs and added a link in the footer to Manage Cookie Preferences.

Cookie Preferences

The modal will not open. The only way I can get the modal to open is by removing my Bootstrap JS. Therefore I assume there is a conflict between the package JS and Bootstrap JS.

I have Googled the issue and see a lot of articles saying that href="javascript:void(0)" should not really be used.

Any ideas what the Bootstrap conflict may be, or is there an alternative way to open the modal rather than using href="javascript:void(0)"?

Thanks in advance.

Ignored paths

Is posible to ignore an entire path?, something like all pages under policy/......

and it include policy/en, policy/es, policy/de

CSS and JS files throw 500 errors

The problem

On page load the CSS and JS files throw a 500 error. The HTML code is visible but display: none; is always active on it. See image below for reference. (the other 500 errors are just images)

Laravel 9, running in docker.

Steps to reproduce:

  1. Installed via composer composer require statikbe/laravel-cookie-consent

  2. Published JS and CSS files as per documentation:
    php artisan vendor:publish --provider="Statikbe\CookieConsent\CookieConsentServiceProvider" --tag="public"

  3. Added stylesheet and js script in base blade.

  4. Added as global middleware:

class Kernel extends HttpKernel
{
    protected $middleware = [
        // ...
        \Statikbe\CookieConsent\CookieConsentMiddleware::class,
    ];

    // ...
}
  1. Cookie button snippet added in footer as per documentation:
    <a href="javascript:void(0)" class="js-lcc-modal-alert">Cookies prefs</a>

  2. Ran php artisan cache:clear and php artisan view:clear

Didn't customize views or translations.

Reference image:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.