• /
  • EnglishEspañolFrançais日本語한국어Português
  • 로그인지금 시작하기

Ad tracking for Roku applications

The Roku Video Agent provides ad event monitoring through two different Ad APIs:

Prerequisites

Before enabling ad tracking:

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 object
adIface.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.xml
source/
IMATrackerInterface.brs

Create 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 Function

Track 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 Function

Where 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.

Copyright © 2026 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.