Track ads using JavaScript 3.x track-ads-on-javascript
The following instructions provide guidance for implementation using the 3.x SDKs.
Ad tracking constants
AdBreakStart
AdBreakComplete
AdStart
AdComplete
AdSkip
Implementation steps
-
Identify when the ad break boundary begins, including pre-roll, and create an
AdBreakObject
by using the ad break information.AdBreakObject
reference:table 0-row-3 1-row-3 2-row-3 3-row-3 Variable Name Type Description name
string Non empty string denoting adbreak name (pre-roll, mid-roll, and post-roll). position
number The number position of the ad break starting with 1. startTime
number Playhead value at the start of the ad break. Ad break object creation:
code language-js var adBreakObject = ADB.Media.createAdBreakObject(<ADBREAK_NAME>, <POSITION>, <START_TIME>);
-
Call
trackEvent()
withAdBreakStart
in theMediaHeartbeat
instance to begin tracking the ad break:code language-js tracker.trackEvent(ADB.Media.Event.AdBreakStart, adBreakObject);
-
Identify when the ad starts and create an
AdObject
instance using the ad information.AdObject
reference:table 0-row-3 1-row-3 2-row-3 3-row-3 4-row-3 Variable Name Type Description name
string Non empty string denoting ad name. adId
string Non empty string denoting ad identifier. position
number The number position of the ad within the adbreak, starting with 1. length
number Positive number denoting length of the ad. Ad object creation:
code language-js var adObject = ADB.Media.createAdObject.createAdObject(<AD_NAME>, <AD_ID>, <POSITION>, <LENGTH>);
-
(Optional) Attach standard and/or ad metadata to the media tracking session through context data variables.
-
Custom ad metadata - For custom metadata, create a variable object for the custom data variables and populate with the data for the current ad:
code language-js /* Set context data */ // Standard metadata keys provided by adobe. adMetadata[ADB.Media.AdMetadataKeys] ="Sample Advertiser"; adMetadata[ADB.Media.AdMetadataKeys] = "Sample Campaign"; // Custom metadata keys adMetadata["affiliate"] = "Sample affiliate"; adMetadata["campaign"] = "Sample ad campaign"; adMetadata["creative"] = "Sample creative";
-
Call
trackEvent()
with theAdStart
event in theMediaHeartbeat
instance 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:
code language-js _onAdStart = function() { tracker.trackEvent(ADB.Media.Event.AdStart, adObject, adMetadata); };
-
When the ad playback reaches the end of the ad, call
trackEvent()
with theAdComplete
event:code language-js _onAdComplete = function() { tracker.trackEvent(ADB.Media.Event.AdComplete); };
-
If ad playback did not complete because the user chose to skip the ad, track the
AdSkip
event:code language-js _onAdSkip = function() { tracker.trackEvent(ADB.Media.Event.AdSkip); };
-
If there are any additional ads within the same
AdBreak
, repeat steps 3 through 7 again. -
When the ad break is complete, use the
AdBreakComplete
event to track:code language-js _onAdBreakComplete = function() { tracker.trackEvent(ADB.Media.Event.AdBreakComplete); };
See the tracking scenario VOD playback with pre-roll ads for more information.
Granular ad tracking
The default ad ping interval is 10 seconds
.
You can set up granular ad tracking to enable 1 second
ad tracking.
Syntax
ADB.Media.MediaObjectKey = {
GranularAdTracking: "media.granularadtracking"
}
Example
var mediaObject = ADB.Media.createMediaObject("media-name", "media-id", 60, ADB.Media.StreamType.VOD, ADB.Media.MediaType.Video);
// Enable granular ad tracking
mediaObject[ADB.Media.MediaObjectKey.GranularAdTracking] = true;
tracker.trackSessionStart(mediaObject);