Skip to main content

Listen to SDK Events

Written by Alexandre Dias Da Silva

Our SDK emits events when a user interacts with our banners or our API.

To execute custom actions based on the lifecycle of our banner on your site, you can listen to the different events it emits.

Emitted Events

ready

Emitted when the Axeptio SDK is loaded and initialized.

consent:saved

This event is emitted when consent has been successfully sent and processed by the Axeptio API. The payload contains the user's preferences and metadata describing the consent.

cookies:complete

Event emitted by the Cookies service when Axeptio is aware of vendors that have been accepted or refused. Since this event is used to trigger the execution of selected vendors and scripts, cookies:complete is emitted even if the cookie banner does not appear. If Axeptio finds preferences in the browser's cookies, the SDK emits the event and blocks the banner from being displayed.

axeptio.on("cookies:complete", function (choices) {  if (choices.google_analytics) {    startGoogleAnaytics();  }});

cookies:step:change

When the cookie banner is open, this event is emitted when a user changes step. The payload is an object that contains a property named index representing the index (as an integer) of the step in the steps array. It also contains the step definition (identifier, title, description, list of vendors, etc.).

cookies:step.startTimeout

Emitted when a "Information Screen" type step starts its countdown before moving to the next step.

cookies:step.stopTimeout

Emitted when an "Information Screen" type step reaches the end of its countdown or is stopped by the user.

token:update

The user token can be updated during the session, for example when it is based on an input field or inferred from an AJAX call. This event is emitted when the token contained in the SDK is updated.

overlayOpenWidget

Allows you to imperatively trigger the appearance of the Axeptio button.

overlayOpenCookies

Allows you to imperatively trigger the appearance of the Axeptio cookie banner.

showProcessingDetails

Emitted when the overlay is opened with the details of a data processing. Can be used imperatively to display the Axeptio overlay.

close

Triggered when the overlay is closed. Can be used imperatively to trigger its appearance.

Under the Hood

Our SDK implements a custom EventEmitter class that exposes three methods :

EventEmitter.on

on(event:String, handler:Function, options = {replay: true, once: false}) 

  • The event parameter accepts wildcards * to listen to multiple events at the same time. For example, you can pass cookies:* to receive all events related to the cookie banner.

  • The handler parameter is a function that is called when the event emitter emits an event matching the pattern of the event parameter. The handler receives two arguments :

    1. The payload related to the event

    2. The exact name of the emitted event

  • The options parameter, optional, is an object composed of the following flags :

    • If replay is set to true, past events that were emitted before the handler was defined will cause the handler to be called immediately. If set to false, only future events will trigger a handler call.

    • If once is set to true, the handler will be called only once. Once it has been called, no other event matching the pattern will trigger it again.

EventEmitter.off

off(event:String, handler:Function = undefined)

The off method unsubscribes the specified handler for the specified event, if it is defined as the second parameter of the function. If handler is not defined, each handler listening to the exact event pattern will be removed from the handlers array.

EventEmitter.trigger

trigger(event:String, payload:Object = undefined)

This method is used to trigger an event and transmit data of any type via the payload parameter.

Did this answer your question?