Contact support

Video plugin: use callback functions

Overview

This document explains how to define JavaScript callback functions to execute at specific events.

Define callback functions

Use the callbacks property of the sasVideoData object to define callback functions.


// Define your callback functions
var adBreakBeginCallback = function(someCallbackParameter) {
    // Do something here
};

var adBreakEndCallback = function(someCallbackParameter) {
    // Do something here
};

// Add your callbacks to the configuration object
sas.video.register({
    id: 'myContainer',
    adData: { ... },
    callbacks: {
        adBreakBegin: adBreakBeginCallback,
        adBreakEnd: adBreakEndCallback
    },
    ...
});

// Remove callbacks when they are no longer required
sas.video.removeCallback('adBreakBegin', adBreakBeginCallback);
sas.video.removeCallback('adBreakEnd', adBreakEndCallback);

Available callback functions

The following table describes the available callback keys, their triggers, and their parameters.

Callback key Trigger event Callback parameters
adBegin An ad begins (pre-roll, mid-roll, post-roll, or overlay).
  • controllerID: The identifier of the controller instance executing this callback.
  • state: The ad break type ("preroll", "midroll", "postroll", or "overlay").
  • type: The creative type ("linear" or "nonLinear").
adBreakBegin A linear ad break begins (pre-roll, mid-roll, or post-roll).
  • A string indicating the ad break type ("preroll", "midroll", or "postroll").
  • A string indicating the ID of the integrated player.
adBreakEnd A linear ad break ends (pre-roll, mid-roll, or postroll).
  • A string indicating the ad break type ("preroll", "midroll", or "postroll").
  • A string indicating the ID of the integrated player.
adEnd An ad ends (pre-roll, mid-roll, post-roll, or overlay).
  • controllerID: The identifier of the controller instance executing this callback.
  • state: The ad break type ("preroll", "midroll", "postroll", or "overlay").
  • type: The creative type ("linear" or "nonLinear").
adError No ad plays due to an error, for example: loading, parsing, or timeout error. It can be triggered only once per ad break and only if no ads were played in the entire ad break.
  • controllerID: The identifier of the controller instance executing this callback.
  • errorCode: The specific error code.
  • state: The ad break type ("preroll", "midroll", "postroll", or "overlay").
contentEnd The video content finishes.
  • controllerID: The identifier of the controller instance executing this callback.
singleError An error occurs (for example: loading, parsing, or timeout error). It can be triggered multiple times per ad break. It provides information about all errors that occur during an ad break. For example, if a specific format is not supported and a passback ad is used, this callback will be called with errorCode 403.
  • errorCode: The specific error code.
  • insertionID: The related insertion ID (null if not applicable).
  • pageID: The page identifier (null if the pageID property isn't defined in the ad request).
videoEnd The entire video experience ends (content is over and there is no post-roll or the last post-roll ended).
  • controllerID: The identifier of the controller instance executing this callback.

Add VAST event callbacks to insertion 

VAST events, as specified in the VAST specification include events such as start, firstQuartile, midpoint, thirdQuartile, complete, mute, unmute, or pause.

You can add callback functions to the insertion that are triggered when the system tracks the according VAST event.

Proceed as follows:

  1. Sign in to Equativ's Monetization Platform and open the insertion.
  2. Go to the Creative template section.
  3. Place the callbacks in <script> tags and name them according to the pattern: [tracking-key]InsertionCallback. For example, startInsertionCallback.
  4. Paste the script into the Custom script field.
  5. Save and put the insertion online.

The system removes these functions from the page once the ad finishes.