---
title: Get started with Roku agent
source: https://docs.newrelic.com/docs/streaming-video-&-ads/installation/roku/get-started-with-roku
---

The New Relic Roku Agent is designed to monitor the behavior of Roku applications, focusing on system-level and video-related events. It uses the Event API to send data via a REST interface, supporting five types of events:

-   **ConnectedDeviceSystem**: System events
-   **VideoAction**: Video events
-   **VideoErrorAction**: Error events
-   **VideoAdAction**: Ad events
-   **VideoCustomAction**: Custom events

## Prerequisites

Before you install the Streaming Video & Ads agent for Roku, ensure you have:

-   Your New Relic [account ID](https://docs.newrelic.com/docs/accounts-partnerships/accounts/account-setup/account-id)
-   Your New Relic license key
-   Reviewed the [Streaming Video & Ads agent compatibility requirements](https://docs.newrelic.com/docs/streaming-video-&-ads/installation/compatibility-requirements)

## Install the Roku agent

### Download and extract package

Download the Roku Video Agent package and unzip it to access the following file structure:

```brightscript
components/NewRelicAgent/
    NRAgent.brs
    NRAgent.xml
    NRTask.brs
    NRTask.xml
source/
    NewRelicAgent.brs
```

### Copy files to your project

Copy the `NewRelicAgent` folder to the `components` directory and the `NewRelicAgent.brs` file to the `source` directory of your Roku app project.

### Initialize the agent

Initialize the New Relic Agent in your main BrightScript file (e.g., `Main.brs`):

```brightscript
m.nr = NewRelic("ACCOUNT ID", "LICENSE KEY")
```

> #### 💡 TIP
>
> **Advanced configuration**: You can optionally specify app name, application token, endpoint region, and logging:
>
> ```brightscript
> m.nr = NewRelic("ACCOUNT ID", "LICENSE KEY", "APP NAME", "APPLICATION TOKEN", "US", true)
> ```
>
> The default endpoint is `US`. For EU data centers, use `EU`, and for JP data centers, use `JP`.

## Enable event captures

The New Relic media agent for Roku devices captures events that occur during the playback of video content. To enable automatic event capture, add these calls to your application:

### Log application start

After initializing the agent, log the application start event:

```brightscript
nrAppStarted(m.nr, aa)
```

### Enable system and video tracking

Activate system and video event tracking:

```brightscript
m.syslog = NewRelicSystemStart(m.port)
```

For video tracking, call `NewRelicVideoStart(m.nr, m.video)` in your scene component.

### Process messages in wait loop

Handle system events in your main wait loop:

```brightscript
if nrProcessMessage(m.nr, msg) = false
    ' Process other messages
end if
```

## Complete example

Below is a complete example of integrating the New Relic Agent into a Roku application:

### Main.brs

```brightscript
sub Main(aa as Object)
    screen = CreateObject("roSGScreen")
    m.port = CreateObject("roMessagePort")
    screen.setMessagePort(m.port)

    'Create the main scene that contains a video player
    scene = screen.CreateScene("VideoScene")
    screen.show()

    'Init New Relic Agent
    m.nr = NewRelic("ACCOUNT ID", "LICENSE KEY")

    'Send APP_STARTED event
    nrAppStarted(m.nr, aa)

    'Pass NewRelicAgent object to the main scene
    scene.setField("nr", m.nr)

    'Activate system tracking
    m.syslog = NewRelicSystemStart(m.port)

    while (true)
        msg = wait(0, m.port)
        if nrProcessMessage(m.nr, msg) = false
            'It is not a system message captured by New Relic Agent
            if type(msg) = "roPosterScreenEvent"
                if msg.isScreenClosed()
                    exit while
                end if
            end if
        end if
    end while
end sub
```

### VideoScene.xml

```xml
<?xml version="1.0" encoding="utf-8" ?>
<component name="VideoScene" extends="Scene">
	<interface>
		<!-- Field used to pass the NewRelicAgent object to the scene -->
		<field id="nr" type="node" onChange="nrRefUpdated" />
	</interface>

	<children>
		<Video
			id="myVideo"
			translation="[0,0]"
		/>
	</children>

	<!-- New Relic Agent Interface -->
	<script type="text/brightscript" uri="pkg:/source/NewRelicAgent.brs"/>

	<script type="text/brightscript" uri="pkg:/components/VideoScene.brs"/>
</component>
```

### VideoScene.brs

```brightscript
sub init()
    m.top.setFocus(true)
    setupVideoPlayer()
end sub

function nrRefUpdated()
    m.nr = m.top.nr

    'Activate video tracking
    NewRelicVideoStart(m.nr, m.video)
end function

function setupVideoPlayer()
    videoUrl = "http://..."
    videoContent = createObject("RoSGNode", "ContentNode")
    videoContent.url = videoUrl
    videoContent.title = "Any Video"
    m.video = m.top.findNode("myVideo")
    m.video.content = videoContent
    m.video.control = "play"
end function
```

## What's next?

After installing the Roku agent, explore these resources to get the most out of your streaming video monitoring:

-   [Roku Agent API reference](https://docs.newrelic.com/docs/streaming-video-&-ads/installation/roku/agent-api/api-agent): Explore the complete API for custom events, metrics, and advanced configuration
-   [Ad tracking for Roku](https://docs.newrelic.com/docs/streaming-video-&-ads/installation/roku/ad-tracking): Set up monitoring for RAF and Google IMA ad events
-   [View your data in New Relic](https://docs.newrelic.com/docs/streaming-video-&-ads/view-data-in-newrelic/streaming-video-&-ads-features): Explore video and ad playback telemetry across all platforms
