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.

Event listeners

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.

Didomi.on

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.

React

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}
/>

Event types

This section presents a comprehensive list of the event types exposed by the Didomi SDK and usage examples.

api.error

Triggered when an error happens while sending an HTTP request to our API for collecting consents, events, metrics, etc.

Listener parameters

context object that contains the following properties:

Key

Description

reason

The reason for the request error.

Possible values: - request.failure when the request fails to be sent for any reason (timeout, no connection, blocked by an extension, etc.) - response.error when we received an error response from the server based on the HTTP response code (>= 400)

id

An ID identifying the request that failed. Possible values: - createEvent: HTTP request to collect an event after a user action (consent changed, pageview, etc.) - createSignature: HTTP request to sign a Didomi Consent String - getSyncData: HTTP request to get user choices from the backend (sync)

Example

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'api.error',
  listener: function ({ id, reason }) {
    // An API error happened
  }
});

consent.changed

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

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'consent.changed',
  listener: function (context) {
    // The user consent status has changed
  }
});

consent.pendingchanged (Currently only used for preference center)

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

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'consent.pendingchanged',
  listener: function ({ pendingConsents }) {
    // The number of pending consent has changed
  }
});

integrations.consentpassedtodfp

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

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)
    }
  }
});

notice.backdropclick

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

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'notice.backdropclick',
  listener: function () {
    // Your event listener
  }
});

notice.clickagree

Triggered when the user clicks on the Agree and close button of a consent notice.

Listener parameters

None

Example

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'notice.clickagree',
  listener: function () {
    // The user has clicked on the "Agree and close" button
  }
});

notice.clickclose

Triggered when the user clicks on the Close icon of a consent notice with format Popup.

Listener parameters

None

Example

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'notice.clickclose',
  listener: function () {
    // The user has clicked on the Close button
  }
});

notice.clickdisagree

Triggered when the user clicks on the Decline button of a consent notice.

Listener parameters

None

Example

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'notice.clickdisagree',
  listener: function () {
    // The user has clicked on the "Decline" button
  }
});

notice.clickmoreinfo

Does not trigger for CCPA

Triggered when the user clicks on the More information link of a consent notice.

Listener parameters

None

Example

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'notice.clickmoreinfo',
  listener: function () {
    // The user has clicked on the "More information" link
  }
});

notice.clickviewvendors

Does not trigger for CCPA

Triggered when the user clicks on the View our partners link of a consent notice.

Listener parameters

None

Example

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'notice.clickviewvendors',
  listener: function () {
    // The user has clicked on the "View our partners" link
  }
});

notice.hidden

Triggered when the user closes the consent notice.

Listener parameters

None

Example

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'notice.hidden',
  listener: function () {
    // The notice has been hidden
  }
});

notice.shown

Triggered when the consent notice gets shown to the user.

Listener parameters

None

Example

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'notice.shown',
  listener: function () {
    // The notice has been shown
  }
});

preferences.clickagreetoall

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

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'preferences.clickagreetoall',
  listener: function () {
    // The user has clicked on the "Agree to all" button 
  }
});

preferences.clickcategoryagree

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

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
  }
});

preferences.clickcategorydisagree

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

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
  }
});

preferences.clickclose

Triggered when the user clicks on the Close icon of the Preferences pop-in.

Listener parameters

None

Example

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'preferences.clickclose',
  listener: function () {
    // The user has clicked on the "Close" icon
  }
});

preferences.clickdisagreetoall

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

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'preferences.clickdisagreetoall',
  listener: function () {
    // The user has clicked on the "Disagree to all" button
  }
});

preferences.clickpurposeagree

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

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
  }
});

preferences.clickpurposedisagree

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

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
  }
});

preferences.clicksavechoices

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

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'preferences.clicksavechoices',
  listener: function () {
    // The user has clicked on the "Save" button
  }
});

preferences.clickvendoragree

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

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
  }
});

preferences.clickvendordisagree

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

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
  }
});

preferences.clickvendorsavechoices

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

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'preferences.clickvendorsavechoices',
  listener: function () {
    // The user has clicked on the "Save" button
  }
});

preferences.clickviewvendors

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

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'preferences.clickviewvendors',
  listener: function () {
    // The user has clicked on the "View vendors" link
  }
});

preferences.hidden

Triggered when the user closes the Preferences pop-in.

Listener parameters

None

Example

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'preferences.hidden',
  listener: function () {
    // The Preferences pop-in has been hidden
  }
});

preferences.shown

Triggered when the Preferences pop-in gets shown to the user.

Listener parameters

None

Example

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'preferences.shown',
  listener: function () {
    // The Preferences pop-in has been shown
  }
});

sync.ready

Triggered when the syncing process is done on the page and the SDK is ready.

This event is meant to be a replacement to window.didomiOnReady when you need to wait for the sync process to be complete and for the SDK to be ready on the page.

It is fired in every case:

  • When syncing is disabled

  • When syncing is enabled but not required (ie the user information is recent enough)

  • When syncing is enabled and has happened (including in error cases)

Listener parameters

None

Example

window.didomiEventListeners = window.didomiEventListeners || [];
window.didomiEventListeners.push({
  event: 'sync.ready',
  listener: function () {
    // The SDK is ready and syncing is done
  }
});

Last updated