https://github.com/statikbe/craft-cookie-banner
https://github.com/statikbe/craft-cookie-banner
craft-plugin craftcms
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/statikbe/craft-cookie-banner
- Owner: statikbe
- Created: 2021-09-15T09:04:32.000Z (almost 5 years ago)
- Default Branch: develop
- Last Pushed: 2024-11-21T14:39:37.000Z (over 1 year ago)
- Last Synced: 2025-03-28T20:37:10.231Z (about 1 year ago)
- Topics: craft-plugin, craftcms
- Language: PHP
- Size: 321 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.MD
- Changelog: CHANGELOG.MD
Awesome Lists containing this project
README
# Cookie banner for Craft CMS 3.x
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:
```console
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.
```PHP
{{ 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:
```PHP
{{ craft.cookieBanner.render({
modal: '_site/_snippet/_cookie/_modal',
banner: '_site/_snippet/_cookie/_banner',
overlay: '
',
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](https://github.com/statikbe/craft-cookie-banner/blob/master/src/templates/_modal.twig), [banner](https://github.com/statikbe/craft-cookie-banner/blob/master/src/templates/_banner.twig) and [overlay](https://github.com/statikbe/craft-cookie-banner/blob/develop/src/templates/_overlay.twig) 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:
```HTML
{{ 'Cookie settings'|t }}
```
## 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:
```js
window.addEventListener('cookie-closed', () => {
console.log('cookie-closed');
});
```