mirror of
https://github.com/infinum/cookies_eu
synced 2023-03-27 23:21:16 -04:00
Add support for an optional hook to know when cookies were acknowledged.
This fixes https://github.com/infinum/cookies_eu/issues/90
This commit is contained in:
parent
3f91806082
commit
82167b3e3d
2 changed files with 12 additions and 0 deletions
10
README.md
10
README.md
|
@ -101,6 +101,16 @@ If you wish to customize the style of the div the classes are:
|
|||
|
||||
If you wish to customize the HTML, create a folder `cookies_eu`, create a partial `_consent_banner.html.erb` and paste the HTML from [here](app/views/cookies_eu/_consent_banner.html.erb)
|
||||
|
||||
If you wish to run some arbitrary code when the user acknowledges the cookie message, you can register a callback. This is useful if you wish to persist the user's preference to the database.
|
||||
|
||||
```javascript
|
||||
document.addEventListener('cookies-eu-acknowledged', function() {
|
||||
// The user has acknowledged cookies! If they're logged in, make an api call
|
||||
// so we remember their preference.
|
||||
fetch('...');
|
||||
});
|
||||
```
|
||||
|
||||
## Cookies used
|
||||
|
||||
This gem uses a cookie called **cookie_eu_consented** to track whether a user has accepted the cookie notice and whether it needs to be shown again or not.
|
||||
|
|
|
@ -29,6 +29,8 @@ var cookiesEu = {
|
|||
|
||||
var container = document.querySelector('.js-cookies-eu');
|
||||
container.parentNode.removeChild(container);
|
||||
|
||||
document.dispatchEvent(new CustomEvent('cookies-eu-acknowledged'));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue