Show Menu
TOPICS×

Track ads using JavaScript 3.x

The following instructions provide guidance for implementation using the 3.x SDKs. If you are implementing any previous versions of the SDK, you can download the Developers Guides here: Download SDKs.

Ad tracking constants

Constant name
Description  
AdBreakStart
Constant for tracking AdBreak Start event
AdBreakComplete
Constant for tracking AdBreak Complete event
AdStart
Constant for tracking Ad Start event
AdComplete
Constant for tracking Ad Complete event
AdSkip
Constant for tracking Ad Skip event

Implementation steps

  1. Identify when the ad break boundary begins, including pre-roll, and create an
    AdBreakObject
    by using the ad break information.
    AdBreakObject
    reference:
    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:
    var adBreakObject = ADB.Media.createAdBreakObject(<ADBREAK_NAME>, <POSITION>, <START_TIME>);
  2. Call
    trackEvent()
    with
    AdBreakStart
    in the
    MediaHeartbeat
    instance to begin tracking the ad break:
    tracker.trackEvent(ADB.Media.Event.AdBreakStart, adBreakObject);
  3. Identify when the ad starts and create an
    AdObject
    instance using the ad information.
    AdObject
    reference:
    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:
    var adObject = ADB.Media.createAdObject.createAdObject(<AD_NAME>, <AD_ID>, <POSITION>, <LENGTH>);
  4. Optionally 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:
      /* 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";
  5. Call
    trackEvent()
    with the
    AdStart
    event in the
    MediaHeartbeat
    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:
    _onAdStart = function() { tracker.trackEvent(ADB.Media.Event.AdStart, adObject, adMetadata); };
  6. When the ad playback reaches the end of the ad, call
    trackEvent()
    with the
    AdComplete
    event:
    _onAdComplete = function() { tracker.trackEvent(ADB.Media.Event.AdComplete); };
  7. If ad playback did not complete because the user chose to skip the ad, track the
    AdSkip
    event:
    _onAdSkip = function() { tracker.trackEvent(ADB.Media.Event.AdSkip); };
  8. If there are any additional ads within the same
    AdBreak
    , repeat steps 3 through 7 again.
  9. When the ad break is complete, use the
    AdBreakComplete
    event to track:
    _onAdBreakComplete = function() { tracker.trackEvent(ADB.Media.Event.AdBreakComplete); };
See the tracking scenario VOD playback with pre-roll ads for more information.