JavaScript API
The JavaScript API lets your scripts wait for the banner, know the visitor's choice and react when it changes.
Use this API when a script in your theme or in a module depends on the banner. For example, to:
- keep your own window from covering the banner;
- start a process after the visitor's choice;
- check their consent to a partner.
To send events to GA4, see dataLayer events and Measure clicks with data-kt attributes instead.
Getting the API #
window.kixelltagOnReady = window.kixelltagOnReady || [];
window.kixelltagOnReady.push(function (KixellTag) {
// Your code here
});
- The function receives the
KixellTagobject. It is called as soon as the module is ready, whatever order the scripts load in. - Added after the module has loaded, it is called at once.
- Always go through the
kixelltagOnReadyqueue.
Methods #
| Method | Role |
|---|---|
KixellTag.on(event, function) |
Calls the function each time the event fires. An event that already happened on the page is replayed to it at once. Use the names in the table below |
KixellTag.hasConsent(partner) |
Returns true if the visitor gave consent to this partner, false otherwise and until they have chosen. Legitimate interest alone does not count |
You name the partner by its ID, for example iab:755 or kcv:143, or by the key a module declared. The ID prefixes are explained in Triggering consent events.
Events #
| Event | When | The function receives |
|---|---|---|
popupVisible |
When the banner opens and closes. On page load, false if the visitor has already chosen |
true or false |
kixelltag_consent_state |
When the banner starts, then after each recorded choice | { chosen, vendors_consent }: whether the visitor has chosen, and the list of accepted partners |
kixelltag_consent_ready |
On page load if a choice is recorded, otherwise after the choice. Then after each new choice | The object pushed into the dataLayer |
kixelltag_consent_chose |
On the visitor's first choice | The object pushed into the dataLayer |
kixelltag_consent_updated |
On each choice | The object pushed into the dataLayer, with kixelltag.vendors_consent and kixelltag.vendors_denied |
kixelltag_page_view |
On every page, after the consent event | The object pushed into the dataLayer |
For kixelltag_consent_state, a function added late only gets the last state. The other events are replayed to it from the start of the page.
The order of the kixelltag_consent_* events and their data are detailed in Triggering consent events.
Examples #
window.kixelltagOnReady = window.kixelltagOnReady || [];
window.kixelltagOnReady.push(function (KixellTag) {
KixellTag.on('popupVisible', function(isVisible) {
console.log("PopupState: ", (isVisible ? 'visible' : 'not visible'));
if (!isVisible) {
// The banner is no longer shown: open your window here
}
});
});
Your window (newsletter, age check, promo code) then opens without covering the banner.
window.kixelltagOnReady = window.kixelltagOnReady || [];
window.kixelltagOnReady.push(function (KixellTag) {
KixellTag.on('kixelltag_consent_ready', function() {
// Consent Mode is up to date: run your script here
});
});
The function runs again if the visitor changes their choice on the same page.
window.kixelltagOnReady = window.kixelltagOnReady || [];
window.kixelltagOnReady.push(function (KixellTag) {
KixellTag.on('kixelltag_consent_state', function (state) {
if (!state.chosen) {
return; // No choice yet: start nothing
}
if (KixellTag.hasConsent('iab:755')) {
// Consent given: start your process
} else {
// No consent: stop it and delete what it stored
}
});
});
This function can run several times on a page, on each new choice: write it so that a second call starts nothing again.
Server side
PrestaShop modules also have hooks: actionKixellTagEnrichItems to enrich the dataLayer products (see Server-side enrichment), actionKixellTagRegisterVendors to declare the module's partner and actionKixellTagConsent to know the visitor's choice (see Modules and consent).
Missing or wrong information? Tell the support team