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:
didomiEventListeners (Recommended)
You can register events by adding them to the special window.didomiEventListeners
array:
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:
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:
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:
- createEventPageview
: HTTP request to collect an event after a page view
- createEventConsentAsked
: HTTP request to collect an event after consent was asked
- createEventConsentGiven
: HTTP request to collect an event after consent was given
- createEventUIAction
: HTTP request to collect an event after a interaction with the UI
- createEventSyncAcknowledged
: HTTP request to collect an event after sync is acknowledged
- getRemoteConsentUser
: HTTP request to get the remote consent
- requestAuthentication
: HTTP request to request authentication
- sendMessage
: HTTP request to send a login message (remote consent flow)
- verifyOtpCode
: HTTP request to send and verify an OTP verification code
- createSignature
: HTTP request to sign a Didomi Consent String
- getSyncData
: HTTP request to get user choices from the backend (sync)
Example
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
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
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
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
notice.clickagree
Triggered when the user clicks on the Agree and close
button of a consent notice.
Listener parameters
None
Example
notice.clickclose
Triggered when the user clicks on the Close icon of a consent notice with format Popup.
Listener parameters
None
Example
notice.clickdisagree
Triggered when the user clicks on the Decline
button of a consent notice.
Listener parameters
None
Example
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
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
notice.hidden
Triggered when the user closes the consent notice.
Listener parameters
None
Example
notice.shown
Triggered when the consent notice gets shown to the user.
Listener parameters
None
Example
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
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
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
preferences.clickclose
Triggered when the user clicks on the Close icon of the Preferences pop-in.
Listener parameters
None
Example
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
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
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
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
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
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
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
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
preferences.hidden
Triggered when the user closes the Preferences pop-in.
Listener parameters
None
Example
preferences.shown
Triggered when the Preferences pop-in gets shown to the user.
Listener parameters
None
Example
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
SyncReadyEvent
object
statusApplied
boolean
Indicates if the user status has been applied locally from the remote Didomi backend. true
if the user status was applied from the remote, false
otherwise.
syncAcknowledged
Function
Callback that can be used to communicate to the Didomi servers that the synchronization has been communicated to the user. Returns true
if the API event was successfully sent, false
otherwise.
syncError
undefined | string
An error message if the sync failed
Example
Last updated