Custom events
Option 1: Wrap your custom events
window.didomiOnReady = window.didomiOnReady || [];
window.didomiOnReady.push(function (Didomi) {
// Fire your custom event(s)
dataLayer.push({'event': 'custom_event'});
});Option 2: Condition your custom events
function fireCustomEvents(consentGiven) {
if (consentGiven === true) {
// Fire your custom event(s) because the user has given consent
dataLayer.push({'event': 'custom_event'});
}
}
window.didomiOnReady = window.didomiOnReady || [];
window.didomiOnReady.push(function (Didomi) {
// The SDK is done loading, check the user status for a given vendor
const consentGiven = Didomi.getCurrentUserStatus().vendors['vendor-id']?.enabled;
if (consentGiven === true) {
// The user has enabled that vendor, fire the custom events
fireCustomEvents(consentGiven);
} else {
// Subscribe to the consent.changed event to get notified when the consent status changes
Didomi.on('consent.changed', function () {
// The consent status of the user has changed, check again
fireCustomEvents(Didomi.getCurrentUserStatus().vendors['vendor-id']?.enabled);
});
}
});Last updated