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. As ads are served, it fires messages for a range of events.

You can add the ados.on() function to your JavaScript ad code to listen for those 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, meaning 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 ImpressionCounted message. The message data carries the impression shim, which holds the name of the div and the userkey in its uk field. Each time the event fires, the callback logs the div name and userkey to the JS console, for every impression loaded on the page:

user key for azk123456 is: ue-29thd03

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