Track ads on Roku
- Topics:
- Media Analytics
CREATED FOR:
- User
- Admin
- Developer
The following instructions provide guidance for implementation using the 2.x 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
-
Identify when the ad break boundary begins, including pre-roll, and create an
AdBreakObject
by using the ad break information.AdBreakObject
reference:Variable Name Description Required name
Ad break name such as pre-roll, mid-roll, and post-roll. Yes position
The number position of the ad break starting with 1. Yes startTime
Playhead value at the start of the ad break. Yes ‘ Create an adbreak info object adBreakInfo = adb_media_init_adbreakinfo() adBreakInfo.name = <ADBREAK_NAME> adBreakInfo.startTime = <START_TIME> adBreakInfo.position = <POSITION>
-
Call
trackEvent()
withAdBreakStart
in theMediaHeartbeat
instance to begin tracking the ad break:contextData = {} ADBMobile().mediaTrackEvent(MEDIA_AD_BREAK_START, adBreakInfo, contextData)
-
Identify when the ad asset starts and create an
AdObject
instance using the ad information.adInfo = adb_media_init_adinfo(ad.title, ad.id, ad.position, ad.duration)
-
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 asset:
contextData = {} contextData["adinfo1"] = "adinfo2" contextData["adinfo2"] = "adinfo2"
-
Call
trackEvent()
with theAdStart
event in theMediaHeartbeat
instance to begin tracking the ad playback:ADBMobile().mediaTrackEvent(ADBMobile().MEDIA_AD_START, adInfo, contextData)
-
When the ad asset playback reaches the end of the ad, call
trackEvent()
with theAdComplete
event.standardAdMetadata = {} contextData = {} ADBMobile().mediaTrackEvent(ADBMobile().MEDIA_AD_COMPLETE, adInfo, contextData)
-
If ad playback did not complete because the user chose to skip the ad, track the
AdSkip
event:contextData = {} ADBMobile().mediaTrackEvent(ADBMobile().MEDIA_AD_SKIP, adInfo, contextData
-
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:contextData = {} ADBMobile().mediaTrackEvent(MEDIA_AD_BREAK_COMPLETE, adBreakInfo, contextData)
See the tracking scenario VOD playback with pre-roll ads for more information.