Events

The Didomi SDK triggers various events to notify you that the user has taken some action (changed their consent status, open the preferences screen, etc.) or that an important event has happened.

This section describes what events are available and how to subscribe to them.

addEventListener

Add an event listener to catch events triggered by the SDK. Events listeners allow you to react to different events of interest. This function is safe to call before the ready event has been triggered.

Requires SDK to be initialized

No.

Parameters

Name

Type

Description

eventListener

EventListener

The event listener. An instance of a subclass of EventListener

Returns

Nothing

Example

let didomiEventListener = EventListener()

didomiEventListener.onConsentChanged = { event in
    // The consent status of the user has changed
}

didomiEventListener.onHideNotice = { event in
    // The notice is being hidden
}

didomiEventListener.onShowNotice = { event in
    // The notice is being shown
}

Didomi.shared.addEventListener(listener: didomiEventListener)

Event types

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

onConsentChanged

Triggered when a consent is given or withdrawn by the user. It's only triggered when the consent status actually changes. For instance, if the user saves consents without adding/removing any consent then this does not get called.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onConsentChanged = { event in
    // The consent status of the user has changed
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onHideNotice

Triggered when the consent notice is hidden. If you have disabled our default consent notice to replace it with your own, you need to hide your custom notice when this event gets triggered.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onHideNotice = { event in
    // The notice is being hidden
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onShowNotice

Triggered when the consent notice gets displayed. If you have disabled our default consent notices to replace them with your own, you need to show your custom notice when this event gets triggered.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onShowNotice = { event in
    // The notice is being shown
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onNoticeClickAgree

Triggered when the user clicks on agree on the notice.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onNoticeClickAgree = { event in
    // Click on agree on notice
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onNoticeClickMoreInfo

Triggered when the user clicks on learn more on the notice.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onNoticeClickMoreInfo = { event in
    // Click on learn more on notice
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onHidePreferences

Triggered when the preferences screen becomes hidden, for example when the user closes it or saves their consent.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onHidePreferences = { event in
    // The preferences screen is being hidden
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onShowPreferences

Triggered when the preferences screen gets displayed.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onShowPreferences = { event in
    // The preferences screen is being shown
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickAgreeToAll

Triggered when the user clicks on agree to all on the preferences popup.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickAgreeToAll = { event in
    // Click on agree to all on preferences popup
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickDisagreeToAll

Triggered when the user clicks on disagree to all on the preferences popup.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickDisagreeToAll = { event in
    // Click on disagree to all on preferences popup
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickPurposeAgree

Triggered when the user agrees to a purpose on the preferences popup.

Listener parameters

  • event: EventType (enum)

  • purposeId: String

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickPurposeAgree = { event, purposeId in
    // Click on agree to a purpose on preferences popup
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickPurposeDisagree

Triggered when the user disagrees to a purpose on the preferences popup. (purposeId provided as a parameter)

Listener parameters

  • event: EventType (enum)

  • purposeId: String

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickPurposeDisagree = { event, purposeId in
    // Click on disagree to a purpose on preferences popup
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickViewVendors

Triggered when the user clicks on view vendors on the preferences popup.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickViewVendors = { event in
    // Click view vendors on purposes view on preferences popup
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickViewSPIPurposes

Triggered when the user clicks on view Sensitive Personal Information from the preferences popup.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickViewSPIPurposes = { event in
    // User clicked on view Sensitive Personal Information from the preferences popup.
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickSaveChoices

Triggered when the user saves his choice on the preferences popup.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickSaveChoices = { event in
    // Click on save on the purposes view on preferences popup
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickVendorAgree

Triggered when the user agrees to a vendor on the preferences popup.

Listener parameters

  • event: EventType (enum)

  • vendorId: String

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickVendorAgree = { event, vendorId in
    // Click on agree to a vendor on preferences popup
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickVendorDisagree

Triggered when the user disagrees to a vendor on the preferences popup.

Listener parameters

  • event: EventType (enum)

  • vendorId: String

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickVendorDisagree = { event, vendorId in
    // Click on disagree to a vendor on preferences popup
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickVendorSaveChoices

This happens when the user saves his choice on the vendors view on the preferences popup.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickVendorSaveChoices = { event in
    // Click on save on the vendors view on preferences popup
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onNoticeClickDisagree

Triggered when the user clicks on disagree on the notice.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onNoticeClickDisagree = { event in
    // Select disagree on the notice
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onNoticeClickViewVendors

Triggered when the user clicks on partners on the notice.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onNoticeClickViewVendors = { event in
    // Select Our Partners on the notice
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onNoticeClickViewSPIPurposes

Triggered when the user clicks on Sensitive Personal Information from the notice.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onNoticeClickViewSPIPurposes = { event in
    // User clicked on Sensitive Personal Information from the notice.
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onNoticeClickPrivacyPolicy

Triggered when the user clicks on privacy policy on the notice (available on TV only).

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onNoticeClickPrivacyPolicy = { event in
    // Select Our Privacy Policy on the notice (tvOS only)
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickAgreeToAllPurposes

Triggered when the user flips ON all purposes switch on the preferences popup.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickAgreeToAllPurposes = { event in
    // Agree to all purposes using the bulk action button on the preferences screen
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickDisagreeToAllPurposes

Triggered when the user flips OFF all purposes switch on the preferences popup.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickDisagreeToAllPurposes = { event in
    // Disagree to all purposes using the bulk action button on the preferences screen
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickAgreeToAllVendors

Triggered when the user flips ON all vendors switch on the preferences popup.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickAgreeToAllVendors = { event in
    // Agree to all vendors using the bulk action button on the preferences screen
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickDisagreeToAllVendors

Triggered when the user flips OFF all vendors switch on the preferences popup.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickDisagreeToAllVendors = { event in
    // Disagree to all vendors using the bulk action button on the preferences screen
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickViewPurposes

Triggered when the user clicks on view purposes on the preferences popup.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickViewPurposes = { event in
    // Select displaying the purposes on the preferences screen
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickSPIPurposeAgree

Triggered when the toggle linked to a Personal Data purpose is set to agree/enabled.

Listener parameters

  • event: EventType (enum)

  • purposeId: String (nullable/optional)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickSPIPurposeAgree = { event, purposeId in
    // Toggle linked to a Personal Data purpose was set to agree/enabled.
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickSPIPurposeDisagree

Triggered when the toggle linked to a Personal Data purpose is set to disagree/disabled.

Listener parameters

  • event: EventType (enum)

  • purposeId: String (nullable/optional)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickSPIPurposeDisagree = { event, purposeId in
    // Toggle linked to a Personal Data purpose was set to disagree/disabled.
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickSPICategoryAgree

Triggered when the toggle linked to a Personal Data category is set to agree/enabled.

Listener parameters

  • event: EventType (enum)

  • categoryId: String (nullable/optional)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickSPICategoryAgree = { event, categoryId in
    // Toggle linked to a Personal Data category was set to agree/enabled.
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickSPICategoryDisagree

Triggered when the toggle linked to a Personal Data category is set to disagree/disabled.

Listener parameters

  • event: EventType (enum)

  • categoryId: String (nullable/optional)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickSPICategoryDisagree = { event, categoryId in
    // Toggle linked to a Personal Data category was set to disagree/disabled.
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onPreferencesClickSPIPurposeSaveChoices

Triggered when the Save button from the Sensitive Personal Information screen is pressed.

Listener parameters

  • event: EventType (enum)

Example

let didomiEventListener = EventListener()

didomiEventListener.onPreferencesClickSPIPurposeSaveChoices = { event in
    // Save button from the Sensitive Personal Information screen was pressed.
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onSyncDone

This event has been deprecated. Use onSyncReady instead.

Triggered when the consent synchronization is successful (Cross-device).

Listener parameters

  • event: EventType (enum)

  • organizationUserId: String (nullable/optional)

Example

let didomiEventListener = EventListener()

didomiEventListener.onSyncDone = { event, organizationUserId in
    // The consent synchronization was successful.
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onSyncError

Triggered when the consent synchronization has failed (Cross-device).

Listener parameters

  • event: EventType (enum)

  • error: String (nullable/optional)

Example

let didomiEventListener = EventListener()

didomiEventListener.onSyncError = { event, error in
    // The consent synchronization has failed.
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onSyncReady

Triggered when the user status synchronization is ready (Cross-device).

Listener parameters

SyncReadyEvent object

PropertyTypeDescription

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

Lambda expression

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.

Example

let didomiEventListener = EventListener()

didomiEventListener.onSyncReady = { event in
    // User status synchronization was successful.
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onLanguageUpdated

Triggered when SDK language has been successfully changed.

Listener parameters

  • event: EventType (enum)

  • languageCode: String (nullable/optional)

Example

let didomiEventListener = EventListener()

didomiEventListener.onLanguageUpdated = { event, languageCode in
    // SDK language has been successfully changed.
}
Didomi.shared.addEventListener(listener: didomiEventListener)

onLanguageUpdateFailed

Triggered when SDK language update has failed. (reason provided as a parameter)

Listener parameters

  • event: EventType (enum)

  • reason: String (nullable/optional)

Example

let didomiEventListener = EventListener()

didomiEventListener.onLanguageUpdateFailed = { event, reason in
    // SDK language update has failed.
}
Didomi.shared.addEventListener(listener: didomiEventListener)

Last updated