This article describes the advanced JavaScript customization options of the Cookie Banner plugin.
This article describes the advanced JavaScript customization options of the Cookie Banner plugin.
The Cookie Banner plugin will fire several JavaScript events. They are listed below.
This event (on document) can be sent to show the consent popup. It will pre-select whatever preference the user has selected before, if any.
document.dispatchEvent(new CustomEvent('wps-cb:show'));
This event (on document) can be sent to hide the consent popup. It will not handle any preference saving by itself; this is handled by the popup buttons.
document.dispatchEvent(new CustomEvent('wps-cb:show'));
This event (on document) is sent whenever the user saves their preferences (via the ‘save’ or ‘accept all’ buttons) or on page load when the banner was shown before.
The event has a single argument, detail, which contains an array of the internal ID of each category selected or selected previously.
document.addEventListener('wps-cb:consent', function(event)
{
if(!event.detail || !Array.isArray(event.detail)) return;
console.log(event.detail); // e.g. ['functional', 'marketing']
});
The Cookie Banner plugin exposes some data about its state.
This property contains an array of the currently accepted internal IDs.
