statikbe / craft-cookie-banner
Cookie banner and modal package
Installs: 9 307
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 0
Open Issues: 6
Type:craft-plugin
Requires
- craftcms/cms: ^5.0.0
- jaybizzle/crawler-detect: ^1.2
Requires (Dev)
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
- dev-develop
- v5.x-dev
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 5.0.0-beta.1
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.0
- 1.1.0
- 1.0.14
- 1.0.13
- 1.0.10
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.2
- 1.0.1
- 1.0.0
- dev-master
- dev-develop-v5
- dev-fixxmlrequest
- dev-sitegroup-stats
- dev-add-ecs-phpstan
- dev-craft3
- dev-feature_tracking
This package is auto-updated.
Last update: 2024-12-21 14:48:10 UTC
README
This is an internal Statik.be plugin for use with our Tag Manager consent management solution.
⚠️ The plugin will only render templates out of the box, it won't do anything to prevent tracking without proper configuration.
Requirements
This plugin requires Craft CMS 3.0.0 or later.
Installation
To install the plugin, follow these instructions:
cd /path/to/project composer require statikbe/craft-cookie-banner ./craft plugin/install cookie-banner
Usage
The plugin uses a Twig function to render the initial popup and the cookie settings modal.
{{ craft.cookieBanner.render() }}
You can also pass an array of options:
- modal: path to the template for the modal
- banner: path to the template for the banner
- overlay: HTML string with styling that will you use as overlay behind the banner
- supportIE: wether or not the Javascript used should be compiled for ES6 or ES5 (defaults to false so using ES6)
- cookiePage: the entry where the cookie policy content is defined. This is used on the modal template to show the possible settings.
For example:
{{ craft.cookieBanner.render({ modal: '_site/_snippet/_cookie/_modal', banner: '_site/_snippet/_cookie/_banner', overlay: '<div class="fixed inset-0 hidden bg-black opacity-80 z-99" id="cookiebanner-overlay"></div>', supportIE: true, cookiePage: craft.entries.section('cookiePolicy').one(), showCookieBanner: (entry.type is defined and entry.type.handle != 'cookiePolicy') }) }}
It's adviced to not overwrite the templates just for styling, only for more fundamental and structural changes.
Modal, banner and overlay templates have generic classes that can be used for styling.
To trigger the settings modal after closing the cookie banner, you can use the following code:
<a href="#" class="js-cookie-settings" role="button">{{ 'Cookie settings'|t }}</a>
Listeners
You can listen to the following events:
cookie-banner-opened
cookie-closed
cookie-modal-opened
cookie-prop-performance-disabled
cookie-prop-performance-enabled
cookie-prop-marketing-disabled
cookie-prop-marketing-enabled
Example:
window.addEventListener('cookie-closed', () => { console.log('cookie-closed'); });