Track ads on Chromecast track-ads-on-chromecast
The following instructions provide guidance for implementation using the 2.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.Ad break object creation: createAdBreakObject
code language-none adBreakInfo = ADBMobile.media.createAdBreakObject("First Ad-Break", 1, AD_BREAK_START_TIME, playerName);
-
Call
trackEvent()
withAdBreakStart
in theMediaHeartbeat
instance to begin tracking the ad break: trackEventcode language-none ADBMobile.media.trackEvent(ADBMobile.media.Event.AdBreakStart, getAdBreakInfo());
-
Identify when the ad asset starts and create an
AdObject
instance using the ad information.Ad object creation: createAdObject
code language-none adInfo = ADBMobile.media.createAdObject("Sample ad", "001", 1, AD_LENGTH);
-
Optionally attach standard and/or ad metadata to the media 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 asset:
-
Call
trackEvent()
with theAdStart
event 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: trackEvent
code language-none ADBMobile.media.trackEvent(ADBMobile.media.Event.AdStart, getAdInfo(), adContextData);
-
When the ad asset playback reaches the end of the ad, call
trackEvent()
with theAdComplete
event: trackEventcode language-none ADBMobile.media.trackEvent(ADBMobile.media.Event.AdComplete);
-
If there are any additional ads within the same
AdBreak
, repeat steps 3 through 6 again. -
When the ad break is complete, use the
AdBreakComplete
event to track: trackEventcode language-none ADBMobile.media.trackEvent(ADBMobile.media.Event.AdBreakComplete, getAdBreakInfo());
See the tracking scenario VOD playback with pre-roll ads for more information.