Events
The Didomi SDK triggers various events to notify you that the user has taken some action (changed their consent status, open the preferences pop-in, etc.) or that an important event has happened.
This section describes what events are available and how to subscribe to them.
The Didomi SDK supports three methods for registering event listeners:
You can register events by adding them to the special
window.didomiEventListeners
array:<script type="text/javascript">
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'event.type',
listener: function () {
// Your event listener
}
});
window.didomiOnReady = window.didomiOnReady || [];
window.didomiOnReady.push(function () {
// Your initialization code (if any)
});
</script>
...
// Embed the Didomi SDK on the page
<script type="text/javascript" src="https://sdk.privacy-center.org/loader.js" async="true"></script>
When the SDK initializes, it collects event listeners from that array and registers them.
You must add your event listeners to that array before the SDK gets embedded on the page and before it is ready to guarantee that you do not miss an event.
You can also add event listeners to that array after the SDK is loaded and the SDK will automatically pick them up but you will miss events that happen during the SDK initialization.
This is the preferred method of registering event listeners as it guarantees that you do not miss events.
Registering your event listeners should be done outside of the
window.didomiOnReady
callback to ensure that you receive all events.If you register events within the
window.didomiOnReady
callback, you will miss some events like the very first notice.shown
that is sent before the window.didomiOnReady
callback gets fired.The SDK also allows you to register event listeners with the
Didomi.on
method exposed in its API:window.didomiOnReady = window.didomiOnReady || [];
window.didomiOnReady.push(function () {
Didomi.on('event.type', function () {
// Your event listener
});
});
While this method is perfectly valid, its main drawback is that your event listener only gets registered once the SDK is ready so that you will miss events fired during the SDK initialization. We recommend using the
didomiEventListeners
method instead.If you are using our React plugin, event listeners can be passed as props to the DidomiSDK component:
consentHasChanged() {
// Do something when the consent from the user has changed
}
preferencesClickPurposeAgree(purposeId) {
// Do something when user agree on a purpose
}
...
<DidomiSDK
...
onConsentChanged={this.consentHasChanged.bind(this)}
onPreferencesClickPurposeAgree={this.preferencesClickPurposeAgree.bind(this}
/>
This section presents a comprehensive list of the event types exposed by the Didomi SDK and usage examples.
Triggered when the user consent status changes either as the result of a user action or an API call.
Listener parameters
context
object that contains the following properties:Key | Description |
action | The user action that triggered the consent change. Possible values: click (explicit click on the buttons), navigate (click to navigate to another page) or external (external call to setUserAgreeToAll) |
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'consent.changed',
listener: function (context) {
// The user consent status has changed
}
});
consentHasChanged() {
// The user consent status has changed
}
...
<DidomiSDK
...
onConsentChanged={this.consentHasChanged.bind(this)}
/>
Triggered when a pending content is added or removed from the queue through the method
Didomi.setPendingConsentForEntityById
or cleared through Didomi.savePendingConsents
.Listener parameters
Key | Description |
pendingConsents | The list of pending consents |
Example
Plain JavaScript
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'consent.pendingchanged',
listener: function ({ pendingConsents }) {
// The number of pending consent has changed
}
});
Triggered when the user consent status has been passed to Google DFP / AdSense / AdExchange. This is only triggered when the Google DFP / AdSense / AdExchange integration is enabled on your website.
Visit that section for more information.
Listener parameters
The listener is provided with a single
data
object that has the following properties:Property | Type | Description |
consentStatus | boolean | Consent status of the user for the vendor Google. true if the user has given consent.false if the user has denied consent.undefined if the user has not made a choice yet. |
index | number | The index is the number of the event on the page.
There is always a first event that gets triggered with index 0 on page load. More events can be triggered if the user changes their consent preferences on the page. The index gets incremented by 1 for every event triggered. |
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'integrations.consentpassedtodfp',
listener: function (data) {
// Consent has been passed to Google
// Load or refresh ads as needed with DFP, Prebid, etc.
// `data.consentStatus` contains the current consent status of the user (true/false/undefined)
// `data.index` contains the index of the event (integer)
if (data.index === 0) {
// This is the very first event on the page that gets triggered on page load
} else {
// This is an event that happens later on the page, after a user action (user giving consent or changing their preferences)
}
}
});
Not available in React yet.
Only triggers when GDPR is active with a pop-in notice
Triggered when the user clicks on the backdrop of a pop-in notice. This event only gets fired when a consent notice of type pop-in is displayed.
Listener parameters
None
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'notice.backdropclick',
listener: function () {
// Your event listener
}
});
noticeBackdropClicked() {
// The user has clicked on the backdrop
}
...
<DidomiSDK
...
onNoticeBackdropclick={this.noticeBackdropClicked.bind(this)}
/>
Triggered when the user clicks on the
Agree and close
button of a consent notice.Listener parameters
None
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'notice.clickagree',
listener: function () {
// The user has clicked on the "Agree and close" button
}
});
noticeAgreeClicked() {
// The user has clicked on the "Agree and close" button
}
...
<DidomiSDK
...
onNoticeClickAgree={this.noticeAgreeClicked.bind(this)}
/>
Triggered when the user clicks on the Close icon of a consent notice with format Popup.
Listener parameters
None
Example
Plain JavaScript
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'notice.clickclose',
listener: function () {
// The user has clicked on the Close button
}
});
Triggered when the user clicks on the
Decline
button of a consent notice.Listener parameters
None
Example
Plain JavaScript
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'notice.clickdisagree',
listener: function () {
// The user has clicked on the "Decline" button
}
});
Does not trigger for CCPA
Triggered when the user clicks on the
More information
link of a consent notice.Listener parameters
None
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'notice.clickmoreinfo',
listener: function () {
// The user has clicked on the "More information" link
}
});
noticeMoreInfoClicked() {
// The user has clicked on the "More information" link
}
...
<DidomiSDK
...
onNoticeClickMoreInfo={this.noticeMoreInfoClicked.bind(this)}
/>
Does not trigger for CCPA
Triggered when the user clicks on the
View our partners
link of a consent notice.Listener parameters
None
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'notice.clickviewvendors',
listener: function () {
// The user has clicked on the "View our partners" link
}
});
noticeViewVendorsClicked() {
// The user has clicked on the "View our partners" link
}
...
<DidomiSDK
...
onNoticeClickViewVendors={this.noticeViewVendorsClicked.bind(this)}
/>
Triggered when the user closes the consent notice.
Listener parameters
None
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'notice.hidden',
listener: function () {
// The notice has been hidden
}
});
noticeHidden() {
// The notice has been hidden
}
...
<DidomiSDK
...
onNoticeHidden={this.noticeHidden.bind(this)}
/>
Triggered when the consent notice gets shown to the user.
Listener parameters
None
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'notice.shown',
listener: function () {
// The notice has been shown
}
});
noticeShown() {
// The notice has been shown
}
...
<DidomiSDK
...
onNoticeShown={this.noticeShown.bind(this)}
/>
Does not trigger for CCPA
Triggered when the user clicks on the
Agree to all
button of the Preferences pop-in.Listener parameters
None
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.clickagreetoall',
listener: function () {
// The user has clicked on the "Agree to all" button
}
});
preferencesAgreeToAllClicked() {
// The user has clicked on the "Agree to all" button
}
...
<DidomiSDK
...
onPreferencesClickAgreeToAll={this.preferencesAgreeToAllClicked.bind(this)}
/>
Does not trigger for CCPA
Triggered when the user enables a specific category on the Preferences pop-in.
This will only be triggered when you are using at least one category / stack.
Listener parameters
The listener is provided with a single
data
object that has the following properties:Property | Type | Description |
categoryId | string | Unique ID of the category that was enabled |
Example
Plain JavaScript
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.clickcategoryagree',
listener: function (data) {
// The user has enabled a specific category
// `data.categoryId` contains the ID of the category
}
});
Does not trigger for CCPA
Triggered when the user disables a specific category on the Preferences pop-in.
This will only be triggered when you are using at least one category / stack.
Listener parameters
The listener is provided with a single
data
object that has the following properties:Property | Type | Description |
categoryId | string | Unique ID of the category that was disabled |
Example
Plain JavaScript
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.clickcategorydisagree',
listener: function (data) {
// The user has enabled a specific category
// `data.categoryId` contains the ID of the category
}
});
Triggered when the user clicks on the Close icon of the Preferences pop-in.

Listener parameters
None
Example
Plain JavaScript
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.clickclose',
listener: function () {
// The user has clicked on the "Close" icon
}
});
Does not trigger for CCPA
Triggered when the user clicks on the
Disagree to all
button of the Preferences pop-in.Listener parameters
None
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.clickdisagreetoall',
listener: function () {
// The user has clicked on the "Disagree to all" button
}
});
preferencesDisagreeToAllClicked() {
// The user has clicked on the "Disagree to all" button
}
...
<DidomiSDK
...
onPreferencesClickDisagreeToAll={this.preferencesDisagreeToAllClicked.bind(this)}
/>
Does not trigger for CCPA
Triggered when the user enables a specific purpose on the Preferences pop-in.
Listener parameters
The listener is provided with a single
data
object that has the following properties:Property | Type | Description |
purposeId | string | Unique ID of the purpose that was enabled |
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.clickpurposeagree',
listener: function (data) {
// The user has enabled a specific purpose
// `data.purposeId` contains the ID of the purpose
}
});
preferencesPurposeAgreeClicked(data) {
// The user has enabled a specific purpose
// `data.purposeId` contains the ID of the purpose
}
...
<DidomiSDK
...
onPreferencesClickPurposeAgree={this.preferencesPurposeAgreeClicked.bind(this)}
/>
Does not trigger for CCPA
Triggered when the user disables a specific purpose on the Preferences pop-in.
Listener parameters
The listener is provided with a single
data
object that has the following properties:Property | Type | Description |
purposeId | string | Unique ID of the purpose that was disabled |
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.clickpurposedisagree',
listener: function (data) {
// The user has enabled a specific purpose
// `data.purposeId` contains the ID of the purpose
}
});
preferencesPurposeDisagreeClicked(data) {
// The user has enabled a specific purpose
// `data.purposeId` contains the ID of the purpose
}
...
<DidomiSDK
...
onPreferencesClickPurposeDisagree={this.preferencesPurposeDisagreeClicked.bind(this)}
/>
Does not trigger for CCPA
Triggered when the user clicks on the
Save
button on the Preferences pop-in (Purposes view).Listener parameters
None
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.clicksavechoices',
listener: function () {
// The user has clicked on the "Save" button
}
});
preferencesSaveChoicesClicked() {
// The user has clicked on the "Save" button
}
...
<DidomiSDK
...
onPreferencesClickSaveChoices={this.preferencesSaveChoicesClicked.bind(this)}
/>
Does not trigger for CCPA
Triggered when the user enables a specific vendor on the Preferences pop-in.
Listener parameters
The listener is provided with a single
data
object that has the following properties:Property | Type | Description |
vendorId | string | Unique ID of the vendor that was enabled |
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.clickvendoragree',
listener: function (data) {
// The user has enabled a specific vendor
// `data.vendorId` contains the ID of the vendor
}
});
preferencesVendorAgreeClicked(data) {
// The user has enabled a specific vendor
// `data.vendorId` contains the ID of the vendor
}
...
<DidomiSDK
...
onPreferencesClickVendorAgree={this.preferencesVendorAgreeClicked.bind(this)}
/>
Does not trigger for CCPA
Triggered when the user disables a specific vendor on the Preferences pop-in.
Listener parameters
The listener is provided with a single
data
object that has the following properties:Property | Type | Description |
vendorId | string | Unique ID of the vendor that was disabled |
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.clickvendordisagree',
listener: function (data) {
// The user has disabled a specific vendor
// `data.vendorId` contains the ID of the vendor
}
});
preferencesVendorDisagreeClicked(data) {
// The user has disabled a specific vendor
// `data.vendorId` contains the ID of the vendor
}
...
<DidomiSDK
...
onPreferencesClickVendorDisagree={this.preferencesVendorDisagreeClicked.bind(this)}
/>
Does not trigger for CCPA
Triggered when the user clicks on the
Save
button of the Preferences pop-in (Vendors view).Listener parameters
None
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.clickvendorsavechoices',
listener: function () {
// The user has clicked on the "Save" button
}
});
preferencesVendorSaveChoicesClicked() {
// The user has clicked on the "Save" button
}
...
<DidomiSDK
...
onPreferencesClickVendorSaveChoices={this.preferencesVendorSaveChoicesClicked.bind(this)}
/>
Does not trigger for CCPA
Triggered when the user clicks on the
View vendors
link of the Preferences pop-in to open the Vendors view..Listener parameters
None
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.clickviewvendors',
listener: function () {
// The user has clicked on the "View vendors" link
}
});
preferencesViewVendorsClicked() {
// The user has clicked on the "View vendors" link
}
...
<DidomiSDK
...
onPreferencesClickViewVendors={this.preferencesViewVendorsClicked.bind(this)}
/>
Triggered when the user closes the Preferences pop-in.
Listener parameters
None
Example
Plain JavaScript
React
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.hidden',
listener: function () {
// The Preferences pop-in has been hidden
}
});
noticeHidden() {
// The notice has been hidden
}
...
<DidomiSDK
...
onNoticeHidden={this.noticeHidden.bind(this)}
/>
Triggered when the Preferences pop-in gets shown to the user.
Listener parameters
None
Example
Plain JavaScript
window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
event: 'preferences.shown',
listener: function () {
// The Preferences pop-in has been shown
}
});
Last modified 3yr ago