Overview overview
The following instructions provide guidance for implementation using the 2.x SDKs.
Ad playback includes tracking ad breaks, ad starts, ad completes, and ad skips. Use the media player’s API to identify key player events and to populate the required and optional ad variables.
Player events player-events
On ad break start
-
Create an
adBreakobject instance for the ad break. For example,adBreakObject. -
Call
trackEventfor the ad break start with youradBreakObject.
On every ad asset start
- Create an ad object instance for the ad asset. For example,
adObject. - Populate the ad metadata,
adCustomMetadata. - Call
trackEventfor the ad start.
On every ad complete
- Call
trackEventfor the ad complete.
On ad skip
- Call
trackEventfor the ad skip.
On ad break complete
- Call
trackEventfor the ad break complete.
Implement ad tracking implement-ad-tracking
Ad tracking constants
AdBreakStartAdBreakCompleteAdStartAdCompleteAdSkipImplementation steps
-
Identify when the ad break boundary begins, including pre-roll, and create an
AdBreakObjectby using the ad break information.AdBreakObjectreference:table 0-row-3 1-row-3 2-row-3 3-row-3 3-align-center 7-align-center 11-align-center 15-align-center Variable Name Description Required nameAd break name such as pre-roll, mid-roll, and post-roll. Yes positionThe number position of the ad break within the content, starting with 1. Yes startTimePlayhead value at the start of the ad break. Yes -
Call
trackEvent()withAdBreakStartin theMediaHeartbeatinstance to begin tracking the ad break. -
Identify when the ad starts and create an
AdObjectinstance using the ad information.AdObjectreference:table 0-row-3 1-row-3 2-row-3 3-row-3 4-row-3 3-align-center 7-align-center 11-align-center 15-align-center 19-align-center Variable Name Description Required nameFriendly name of the ad. Yes adIdUnique identifier for the ad. Yes positionThe number position of the ad within the ad break, starting with 1. Yes lengthAd length Yes -
Optionally attach standard and/or ad metadata to the tracking session through context data variables.
- Standard ad metadata - For standard ad metadata, create a dictionary of standard ad metadata key value pairs using the keys for your platform.
- Custom ad metadata - For custom metadata, create a variable object for the custom data variables and populate with the data for the current ad.
-
Call
trackEvent()with theAdStartevent in theMediaHeartbeatinstance to begin tracking the ad playback.Include a reference to your custom metadata variable (or an empty object) as the third parameter in the event call. While the ad is playing, keep the content playhead (
l:event:playhead) fixed at the position where the ad break began; advancing it during ad playback overstates Content time spent. -
When the ad playback reaches the end of the ad, call
trackEvent()with theAdCompleteevent. -
If ad playback did not complete because the user chose to skip the ad, track the
AdSkipevent. -
If there are any additional ads within the same
AdBreak, repeat steps 3 through 7 again. -
When the ad break is complete, use the
AdBreakCompleteevent to track it.
trackPlay before AdBreakStart and AdStart. The first play ping on main content increments Content starts. If trackPlay is called before the pre-roll ad events fire and the viewer drops out during the ad, Content starts is incremented even though no main content was ever played. For pre-roll scenarios, delay trackPlay until after AdBreakStart and AdStart have been sent.0 throughout the entire ad. For a mid-roll ad that starts at the 5-minute mark, the playhead remains at 300 (seconds) for the duration of the ad.The following sample code utilizes the JavaScript 2.x SDK for an HTML5 media player.
/* Call on ad break start */
if (e.type == "ad break start") {
var adBreakObject = MediaHeartbeat.createAdBreakObject("mid-roll", 2, 500);
this.mediaHeartbeat.trackEvent(MediaHeartbeat.Event.AdBreakStart, adBreakObject);
};
/* Call on ad start */
if (e.type == "ad start") {
var adObject = MediaHeartbeat.createAdObject("PepsiOne", "123456ab", 1, 30);
/* Set custom context data */
var adCustomMetadata = {
affiliate:"Sample affiliate",
campaign:"Sample ad campaign",
creative:"Sample creative"
}
this.mediaHeartbeat.trackEvent(MediaHeartbeat.Event.AdStart, adObject, adCustomMetadata);
};
/* Call on ad complete */
if (e.type == "ad complete") {
this.mediaHeartbeat.trackEvent(MediaHeartbeat.Event.AdComplete);
};
/* Call on ad skip */
if (e.type == "ad skip") {
this.mediaHeartbeat.trackEvent(MediaHeartbeat.Event.AdSkip);
};
/* Call on ad break complete */
if (e.type == "ad break complete") {
this.mediaHeartbeat.trackEvent(MediaHeartbeat.Event.AdBreakComplete);
};