Listening to the Consent JavaScript SDK
The Consent JavaScript SDK differentiates between several situations and triggers specific events you can react to. You can handle these events using either synchronous or asynchronous listener callback functions, depending on your implementation needs.
Synchronous (Generic) Listener
If you are certain that your listener will execute before the main Consent JavaScript SDK snippet loads, you can use a standard browser event listener:
document.addEventListener('<eventname>', function (e) {
console.log(e.detail.<more info>);
});
Replace
<eventname>
with the specific Consent JavaScript SDK event name.Replace
<more info>
with the data property you want to access (see table below in your documentation).
This approach works best when your script execution order is predictable and guaranteed to precede the SDK script execution.
Asynchronous (Specific) Listener
If your implementation cannot guarantee execution before the Consent JavaScript SDK snippet (e.g., when using an external Tag Management System like Google Tag Manager), use the internal Event Listener:
jentis.consent.engine.addEventListener('<eventname>', function (e) {
console.log(e.detail.<more info>);
});
Advantages:
If you miss an event, the Consent JavaScript SDK will detect this and call your callback immediately.
Ideal for asynchronous environments or late-loading scripts.
Best Practice: Writing a Listener That Works in Both Cases
The following approach automatically chooses the best event source depending on whether the Consent JavaScript SDK is already loaded:
if (typeof window.jentis !== "undefined" &&
typeof window.jentis.consent !== "undefined" &&
typeof window.jentis.consent.engine !== "undefined") {
// The SDK is already loaded – register at the engine to avoid missing events.
var oEventBaseObject = window.jentis.consent.engine;
} else {
// SDK not loaded yet – safe to register at the document.
var oEventBaseObject = document;
}
// Listen to the Init Event of the Consent JavaScript SDK.
(function (oMe, oEventBaseObject) {
oEventBaseObject.addEventListener('jentis.consent.engine.init', function (e) {
oMe.consentEngineReady = true;
oMe.startTracking();
});
})(this, oEventBaseObject);
✅ Tip: Always handle both scenarios (SDK already loaded or not yet available) to ensure your tracking logic runs reliably in all environments.
Last updated
Was this helpful?