Our SDK dispatches events when the user interacts with our widgets or our API.
In order to execute custom actions based on the lifecyle of our widget on your site, you can listen to the various events it dispatches.
Events dispatched
ready
Dispatched when Axeptio SDK is loaded and initialized.
consent:saved
This event is dispatched when a consent has been successfully sent and processed by the Axeptio's API. The payload contains the preferences of the user and the metadata describing the consent.
cookies:complete
Event dispatched by the Cookies service when we know which vendors are accepted and which are not. Because this event is used to trigger the launch of selected vendors and scripts, the cookies:complete is dispatched even if the cookie widget doest not pop. If we find preferences inside the browser's cookies, we dispatch the event and discard the widget opening.
axeptio.on('cookies:complete', function(choices){
if(choices.google_analytics){
startGoogleAnaytics()
}
});
cookies:step:change
When the cookie widget is open, this event will be dispatched when a user switches from one screen to another. The payload is an object containing a property named
index
which is the integer index of the step in the array of steps. It also contains the Step definition (identifier, title, description, list of vendors, etc.)
cookies:step.startTimeout
cookies:step.stopTimeout
token:update
The user token can be updated during the session, for example when a user token is based on an input field or deduced from an AJAX call. This event is dispatched when the token contained by the SDK is updated.
overlayOpenWidget
Is used imperatively to trigger the apparition of the Axeptio button.
overlayOpenCookies
Is used imperatively to trigger the apparition of the Axeptio cookies panel.
showProcessingDetails
Dispatched when the overlay is opened with the details of a data processing. Can be used imperatively to trigger the apparition of the Axeptio overlay.
close
Dispatched when the overlay is closed. Can be used imperatively to trigger the apparition of the Axeptio overlay.
Under the hood
Our SDK conforms to 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 *
in order to listen to several events at once. For example, you could pass cookies:*
and subsequentely receive every event related to our Cookie Widget.The
handler
parameter is a function that gets called when the event emitter dispatches an event matching the event
parameter pattern. The handler function will receive two arguments: -
1.The payload attached to the event
-
2.The exact name of the event dispatched
The
options
optional parameter is an object composed of the flags:-
1.If
replay
is set totrue
, past events that have been dispatched before the event handler is set will result in calling the handler function right away. If set tofalse
, only subsequent events will trigger a call to the handler.
-
2.If
once
is set totrue
, the handler will only be called once. After it's been called, a matching event won't call it again.
EventEmitter.off
off(event:String, handler:Function = undefined)
The
off
method will unsubscribe the specified handler
for the specified event
, if it is specified as the second parameter of the function. If handler
is unspecified, every handler function listening to the exact event
pattern will be removed of the handlers array. EventEmitter.trigger
trigger(event:String, payload:Object = undefined)
This method is used to trigger an event, and also allows to send mixed data by specifying the
payload
parameter.