Registering Callbacks From the JavaScript Ad Code

Overview

ados.js is the client-side JavaScript library that Kevel's ad code uses to request and display ads in the browser. ados.js fires a number of messages based on ad serving events.

You can add the ados.on(); function to your JavaScript ad code to listen for events and register callbacks.

Available Events

EventDescription
ImpressionCountedFired when an impression pixel is loaded to the page
loadFired when ados.js is loaded
logFired whenever ados.js logs something to the JS console
passbackExecFired whenever a passback chain renders an ad (note that the ad may include a passback from a 3rd party server, so this may not indicate the final served ad)
passbackLoadFired when a passback chain starts loading
passbackNextFired at each step of the passback chain
passbackTimeoutFired when a passback times out
refreshFired whenever the ad code refreshes i.e. whenever ados_refresh is called
requestStartFired when an ad request is made

Registering Callbacks

The format for using ados.on(); is:

ados.on(message, callback);

For example:

ados.on("ImpressionCounted", function(msg) {
  console.log("user key for " + msg.data.div + " is: " + msg.data.shim.uk);
});

This listens for the message "ImpressionCounted". The message data includes the impression shim, which includes the name of the div and the userkey as the value of the uk field. When the event takes place, the callback logs the divId and userkey for all impressions loaded for the page to the JS console:

user key for azk123456 is: ue-29thd03

If you have any questions about ados.js callbacks, please contact Kevel support.