Stay organized with collections
Save and categorize content based on your preferences.
The Interactive Media Ads (IMA) Dynamic Ad Insertion SDK (DAI) relies on
metadata information embedded in the stream's media segments (in-band metadata),
or in the streaming manifest file (in-manifest metadata) to track viewers'
positions and client-side ad events. Metadata is available from the DAI stream
in different formats, depending on the type of stream being played. The IMA DAI
SDK handles all metadata formats through a single API.
Your app is responsible for capturing metadata and forwarding it to the IMA DAI SDK. The SDK offers the
StreamManager.onMessage()
method to pass this information. This method forwards metadata in the form of a
msg object provided by the roVideo port. These objects are then processed by
the IMA DAI SDK to establish the timing for ad events. It takes a single
argument:
msg: a msg type object provided by the roVideo port.
Metadata sample code
Here's an example of how to handle the metadata from the roVideo port and
pass it to the IMA DAI SDK through StreamManager.onMessage().
Linear DAI HLS streams using the Common Media Application Framework (CMAF) pass
timed metadata through in-band eMSGv1 boxes following the ID3 through
CMAF standard. These eMSG boxes are
embedded at the beginning of each media segment, with each ID3 eMSG containing
a PTS relative to the last discontinuity in the stream.
For IMA Roku, all HLS CMAF streams send in-band ID3 data using the eMSGv0 format.
IMA combines information provided by the eMSGv0 format with information
from the video object.
To enable proper parsing of HLS CMAF stream ID3 events, you must send your
video object in the stream request using
StreamRequest.videoObject.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[[["\u003cp\u003eThe IMA DAI SDK uses metadata embedded within media segments or streaming manifests to track viewer positions and ad events, simplifying ad insertion in live and on-demand content.\u003c/p\u003e\n"],["\u003cp\u003eYour app needs to capture metadata from the roVideo port and forward it to the IMA DAI SDK using the \u003ccode\u003eStreamManager.onMessage()\u003c/code\u003e method for proper ad tracking.\u003c/p\u003e\n"],["\u003cp\u003eHLS CMAF streams utilize in-band eMSGv1 boxes following the ID3 through CMAF standard to pass timed metadata for ad cue points.\u003c/p\u003e\n"],["\u003cp\u003eTo ensure accurate parsing of HLS CMAF stream ID3 events, include the video object in the stream request using \u003ccode\u003eStreamRequest.videoObject\u003c/code\u003e.\u003c/p\u003e\n"]]],["The Interactive Media Ads (IMA) Dynamic Ad Insertion SDK uses in-band or in-manifest metadata to track viewer positions and ad events. Apps capture this metadata and use the `StreamManager.onMessage()` method to forward it to the SDK. This method processes `msg` objects from the roVideo port to time ad events. The example shows a loop that observes video fields, forwards timed metadata to IMA via `onMessage()`, and monitors the video's current position. HLS CMAF streams pass timed metadata via in-band eMSGv1 boxes.\n"],null,["# Handle timed metadata in linear DAI streams\n\nThe Interactive Media Ads (IMA) Dynamic Ad Insertion SDK (DAI) relies on\nmetadata information embedded in the stream's media segments (in-band metadata),\nor in the streaming manifest file (in-manifest metadata) to track viewers'\npositions and client-side ad events. Metadata is available from the DAI stream\nin different formats, depending on the type of stream being played. The IMA DAI\nSDK handles all metadata formats through a single API.\n\nYour app is responsible for capturing metadata and forwarding it to the IMA DAI SDK. The SDK offers the\n[`StreamManager.onMessage()`](/ad-manager/dynamic-ad-insertion/sdk/roku/apis#ima.StreamManager.onMessage)\nmethod to pass this information. This method forwards metadata in the form of a\n`msg` object provided by the roVideo port. These objects are then processed by\nthe IMA DAI SDK to establish the timing for ad events. It takes a single\nargument:\n\n- `msg`: a msg type object provided by the roVideo port.\n\nMetadata sample code\n--------------------\n\nHere's an example of how to handle the metadata from the roVideo port and\npass it to the IMA DAI SDK through `StreamManager.onMessage()`. \n\n Sub runLoop()\n ' Forward all timed metadata events to IMA.\n m.top.video.timedMetaDataSelectionKeys = [\"*\"]\n\n ' Cycle through all the fields and set listeners.\n ' IMPORTANT: Failure to listen to the position and timedmetadata fields could\n ' result in ad impressions not being reported.\n m.port = CreateObject(\"roMessagePort\")\n fields = m.top.video.getFields()\n for each field in fields\n m.top.video.observeField(field, m.port)\n end for\n\n while True\n msg = wait(1000, m.port)\n if m.top.video = invalid\n print \"exiting\"\n exit while\n end if\n\n m.streamManager.onMessage(msg)\n currentTime = m.top.video.position\n If currentTime \u003e 3 And not m.top.adPlaying\n m.top.video.enableTrickPlay = true\n End If\n end while\n End Sub\n\nFor more information on how to incorporate the loop handling stream metadata\ninto your app, see the\n[IMA Roku getting started guide](/ad-manager/dynamic-ad-insertion/sdk/roku). The\n[event listener and stream start section](/ad-manager/dynamic-ad-insertion/sdk/roku#add-event-listeners-and-start-the-stream)\nof the guide contains the metadata handling loop.\n\nHLS CMAF streams\n----------------\n\nLinear DAI HLS streams using the Common Media Application Framework (CMAF) pass\ntimed metadata through in-band eMSGv1 boxes following the [ID3 through\nCMAF](//aomediacodec.github.io/id3-emsg/) standard. These eMSG boxes are\nembedded at the beginning of each media segment, with each ID3 eMSG containing\na PTS relative to the last discontinuity in the stream.\n\nFor IMA Roku, all HLS CMAF streams send in-band ID3 data using the eMSGv0 format.\nIMA combines information provided by the eMSGv0 format with information\nfrom the video object.\n\nTo enable proper parsing of HLS CMAF stream ID3 events, you must send your\nvideo object in the stream request using\n[`StreamRequest.videoObject`](/ad-manager/dynamic-ad-insertion/sdk/roku/apis#ima.StreamRequest.videoObject)."]]