Roku Basic Integration
Include Required Library files
- BranchSdkLibrary.brs
- BranchSdkTask.xml
- BranchSdkTask.brs
Within the input
folder, you will find the following required Branch SDK files:
├── components
│ └── tasks
│ ├── BranchSdkTask.brs
│ └── BranchSdkTask.xml
└── source
└── libs
└── BranchSdkLibrary.brs
- Create a new folder called
libs
in thesource
folder of your application - Copy the
BranchSdkLibrary.brs
file from the Branch repo into your project's newlibs
folder - Create a new folder called
tasks
incomponents
folder of your
application - Copy both the
BranchSdkTask.xml
andBranchSdkTask.brs
files into your project's new
tasks
folder
Configure Branch
- Open the
Main.brs
file of your project which functions as the entry point of SceneGraph application. - Inside the
sub Main()
, or below wherescreen
is declared, add the following line:ConfigureBranchSdk(screen)
(example here) - Next, let's define a new sub below
Main()
sub ConfigureBranchSdk(screen as dynamic)
options = {}
' For future use for advance features in Branch SDK'
options.branchKey = "key_live_TODO_YOUR_BRANCH_KEY_HERE"
options.logLevel = BranchSdkConstants().LOG_LEVEL.DEBUG
options.environment = BranchSdkConstants().ENVIRONMENT.PRODUCTION
' Set Branch SDK configuration parameter as required
screen.getGlobalNode().addFields({branchSdkConfig: options})
end sub
Then be sure to replace key_live_TODO_YOUR_BRANCH_KEY_HERE
with your Branch Key from the Branch Dashboard.
You can see an example of this code here.
Initialize Branch
- Open your file which extends
Scene
, let say itsMainScene.xml
file. - Add new script file path of
BranchSdkLibrary.brs
<script type="text/brightscript" uri="pkg:/source/libs/BranchSdkLibrary.brs"/>
You can see an example of this code here.
- Open
MainScene.brs
file and create instance of the Branch SDK library:
m.branchSdkObj = CreateBranchSdkForSceneGraphApp()
You can see an example of this code here.
- Now do first API call which is InitSession like following:
m.branchSdkObj.initSession(m.global.launchArgs, "OnInitSessionCallbackFunc")
You can see an example of this code here. An example of the callback function can be found here
That's it! Now Roku session count tracking should function, and you'll start to see Roku installs and opens tracked on the Branch Dashboard!
Deep Linking and Attribution
There are two primary ways in which links can trigger the Roku app to respond. Here are curls that indicate the format of these links, which you can modify and use for testing:
/launch/{channel}
curl -d '' 'http://ROKU_LOCAL_IP:8060/launch/dev?contentId=1234&mediaType=movie'
/input
curl -d '' 'http://ROKU_LOCAL_IP:8060/input?contentId=1234&mediaType=movie'
where ROKU_LOCAL_IP
is your Roku's local IP address.
In both cases, please send up the data (contentId, mediaType, and any other query params) to Branch:
m.branchSdkObj.handleInput(data, "OnHandleInputEventCallbackFunc")
Then you can receive deep link data back from Branch's servers, similar to any other Branch SDK. You can see an example of this code here.
Important note
For proper deep linking, please make sure that you are using a correct deeplink format, e.g.: contentId=1234&mediaType=movie
Be sure to discuss your use cases for deep linking and attribution with a Branch team member.
Updated 2 months ago