Track ads on Chromecast track-ads-on-chromecast
The following instructions provide guidance for implementation using the 2.x SDKs.
Ad tracking constants
AdBreakStartAdBreakCompleteAdStartAdCompleteAdSkipImplementation steps
-
Identify when the ad break boundary begins, including pre-roll, and create an
AdBreakObjectby 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()withAdBreakStartin theMediaHeartbeatinstance 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
AdObjectinstance 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 theAdStartevent 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 theAdCompleteevent: 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
AdBreakCompleteevent 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.