JavaScript API
The banner adds a small API on window.BerryCookie for your own code:
| Call | What it does |
|---|---|
BerryCookie.hasConsent(category) | true when the category is accepted (necessary always is). |
BerryCookie.consent | The decision: { id, cats, act, ts, v }, or null before one. |
BerryCookie.mode | optIn, optOut or none for this visitor. |
BerryCookie.show() | Opens the preferences. |
BerryCookie.renew() | Shows the banner again. |
event berrycookie:consent | On window after every decision; event.detail is the decision. |
// Has the visitor accepted statistics?
if (window.BerryCookie?.hasConsent('statistics')) {
startAnalytics();
}
// React to every decision (accept, reject, change)
window.addEventListener('berrycookie:consent', (event) => {
console.log('Accepted categories:', event.detail.cats);
});Need help? [email protected]
Ready to put it on your website?
Install it with one line of code, the Google Tag Manager template or the WordPress plugin.