atlasconsulting/cakephp-cookie-consent

CookieConsent plugin for CakePHP

v1.0.0 2022-05-19 10:44 UTC

This package is auto-updated.

Last update: 2024-09-19 15:51:12 UTC


README

php image image

This plugin helps to remove cookies your app set and on which a user didn't consent. It works reading a configurable cookie that contain information about the categories of cookie accepted by the user. It works out of the box with Cookie Consent.

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require atlasconsulting/cakephp-cookie-consent

Usage

Add the CookieCosentMiddleware to the application middleware queue.

public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
{
    return $middlewareQueue
        // Catch any exceptions in the lower layers,
        // and make an error page/response
        ->add(new ErrorHandlerMiddleware(Configure::read('Error')))

        ->add(new CookieConsentMiddleware([
            'remove' => [
                'preferences' => ['lang'], // remove `lang` cookie if `preferences` category isn't accepted
                'analytics' => ['my_analytics'], // remove `my_analytics` cookie if `analytics` category isn't accepted
            ],
        ]));

        // other middlewares here
}

Configuration

The middleware is configurable with:

[
    'cookieName' => 'cc_cookie',
    'searchIn' => 'level',
    'remove' => [
        'preferences' => [],
        'analytics' => [],
        'targeting' => [],
    ],
]

where

  • cookieName (default cc_cookie), the cookie consent to analyze
  • searchIn (default level), the key to look for in the json string value of cookie. The value must be an array of cookies' categories accepted by the user, for example ['preferences', 'analytics'].
  • remove an array divided by cookie categories that are to remove if not accepted