The Roku Video Agent provides ad event monitoring through two different Ad APIs:
Prerequisites
Before enabling ad tracking:
- Complete Roku agent installation
- Initialize the New Relic Agent (referenced as
m.nrin examples below)
Roku Advertising Framework (RAF)
RAF is integrated within the NRAgent. No additional files are required.
Enable RAF tracking
Pass the NRAgent object (created with NewRelic("ACCOUNT ID", "LICENSE KEY")) to the Ads task using a field. Inside the Ads task, perform the following:
adIface = Roku_Ads()
' Ad Iface setup code...
logFunc = Function(obj = Invalid as Dynamic, evtType = invalid as Dynamic, ctx = invalid as Dynamic) 'Call RAF tracker, passing the event and context nrTrackRAF(obj, evtType, ctx)End Function
' m.top.nr is the reference to the field where we have the NRAgent objectadIface.setTrackingCallback(logFunc, m.top.nr)For a complete usage example, check out the files VideoScene.brs (function setupVideoWithAds()) and AdsTask.brs in the Roku agent package.
Google IMA
Copy required files
Ensure the following files are included in your project directory:
components/NewRelicAgent/trackers IMATracker.brs IMATracker.xmlsource/ IMATrackerInterface.brsCreate IMA tracker
Create the IMA Tracker object:
tracker = IMATracker(m.nr)Where m.nr is the NRAgent object.
Set up ad tracking
Pass the tracker object to the IMA SDK Task using a field and include the script IMATrackerInterface.brs in the task XML. Inside the task, set up the following tracking:
Track ad breaks:
m.player.adBreakStarted = Function(adBreakInfo as Object) ' Ad break start code...
' Send AD_BREAK_START nrSendIMAAdBreakStart(m.top.tracker, adBreakInfo)End Function
m.player.adBreakEnded = Function(adBreakInfo as Object) ' Ad break end code...
' Send AD_BREAK_END nrSendIMAAdBreakEnd(m.top.tracker, adBreakInfo)End FunctionTrack ad events:
m.streamManager.addEventListener(m.sdk.AdEvent.START, startCallback)m.streamManager.addEventListener(m.sdk.AdEvent.FIRST_QUARTILE, firstQuartileCallback)m.streamManager.addEventListener(m.sdk.AdEvent.MIDPOINT, midpointCallback)m.streamManager.addEventListener(m.sdk.AdEvent.THIRD_QUARTILE, thirdQuartileCallback)m.streamManager.addEventListener(m.sdk.AdEvent.COMPLETE, completeCallback)
Function startCallback(ad as Object) as Void ' Send AD_START nrSendIMAAdStart(m.top.tracker, ad)End Function
Function firstQuartileCallback(ad as Object) as Void ' Send AD_QUARTILE (first) nrSendIMAAdFirstQuartile(m.top.tracker, ad)End Function
Function midpointCallback(ad as Object) as Void ' Send AD_QUARTILE (midpoint) nrSendIMAAdMidpoint(m.top.tracker, ad)End Function
Function thirdQuartileCallback(ad as Object) as Void ' Send AD_QUARTILE (third) nrSendIMAAdThirdQuartile(m.top.tracker, ad)End Function
Function completeCallback(ad as Object) as Void ' Send AD_END nrSendIMAAdEnd(m.top.tracker, ad)End FunctionWhere m.top.tracker is the tracker object passed to the task.
For a complete usage example, check out the files VideoScene.brs (function setupVideoWithIMA()) and imasdk.brs in the Roku agent package.