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). |
|
adBreakBegin |
A linear ad break begins (pre-roll, mid-roll, or post-roll). |
|
adBreakEnd |
A linear ad break ends (pre-roll, mid-roll, or postroll). |
|
adEnd |
An ad ends (pre-roll, mid-roll, post-roll, or overlay). |
|
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. |
|
contentEnd |
The video content finishes. |
|
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. |
|
videoEnd |
The entire video experience ends (content is over and there is no post-roll or the last post-roll ended). |
|
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:
- Sign in to Equativ's Monetization Platform and open the insertion.
- Go to the Creative template section.
- Place the callbacks in
<script>tags and name them according to the pattern:[tracking-key]InsertionCallback. For example,startInsertionCallback. - Paste the script into the Custom script field.
- Save and put the insertion online.
The system removes these functions from the page once the ad finishes.
