atlasconsulting / cakephp-cookie-consent
CookieConsent plugin for CakePHP
Installs: 359
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 1
Forks: 1
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=7.4
- ext-json: *
- cakephp/cakephp: ^4.3
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- cakephp/cakephp-codesniffer: ^4.2.0
- phpstan/phpstan: ^1.5
- phpunit/phpunit: ^9
README
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
(defaultcc_cookie
), the cookie consent to analyzesearchIn
(defaultlevel
), 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