Roku Full Reference

All available methods of Branch for your Roku app.

initSession

方法

描述

initSession: function(inputArgs = {}, callbackFunc = "") as void

Initializes your Branch session.

Argument

类型

描述

inputArgs

Object

Input arguments. Typically m.global.launchArgs

callbackFunc

String

Name of the callback function for initialization.

用法示例

sub init()
    ' Other init Configs...'

    ' BRANCH SDK INTEGRATION - Create Instance'
  m.branchSdkObj = CreateBranchSdkForSceneGraphApp()

  if (m.branchSdkObj = invalid) then
    ShowMessageDialog("Failed to initialize Branch SDK!")
  else
    ' BRANCH SDK INTEGRATION - Initialize Branch'
    m.branchSdkObj.initSession(m.global.launchArgs, "OnInitSessionCallbackFunc")
  end if
    
    ' Other init Configs...'
end sub


function OnInitSessionCallbackFunc(event as object) as void
    data = event.GetData()
  print "OnInitSessionCallbackFunc: " data
    
  if (data <> invalid) then
    m.lSessionApiResultDetails.text = FormatJson(data)
  else
    m.lSessionApiResultDetails.text = "initSession API response received!"
  end if
    
  message = "API Succeeded!"
  if (data.error <> invalid)
    message = "API Error!"
  else
    ShowMessageDialog("initSession" + " " + message)
  end if
end function

setPreinstallData

方法

描述

setPreinstallData: function(campaign = "", partner = "") as void

If your app is preinstalled on Roku devices, for builds distributed to Roku, use this method to set configuration settings for your Branch session to attribute the pre-install to a specific partner.

Argument

类型

描述

campaign

String

Name of the campaign.

partner

String

Name of the partner. This will typically be a $3p value. Reach out to your Branch account manager to retrieve the $3p value.

sub init()
    ' BRANCH SDK INTEGRATION - Create Instance'
    m.branchSdkObj = CreateBranchSdkForSceneGraphApp()
    if (m.branchSdkObj = invalid) then
        ShowMessageDialog("Failed to initialize Branch SDK!")
    else
        print "MainScene : setPreinstallData"
        ' BRANCH SDK INTEGRATION - Call API'
        m.branchSdkObj.setPreinstallData("MyCampaign", "MyPartner")
        InitSession_Clicked()
    end if
end sub

handleInput

方法

描述

handleInput: function(inputArgs = {}, callbackFunc = "") as void

Handles an input to retrieve deep linking data

Argument

类型

描述

inputArgs

Object

Input arguments. Typically m.global.launchArgs

callbackFunc

String

Name of the callback function for initialization.

用法示例

sub HandleInput_Clicked()
    if (m.branchSdkObj = invalid) then
        ShowMessageDialog("Branch SDK is not initialized!")
        return
    end if

    print "Calling Branch HandleInput API"
    print "m.global.launchArgs : " m.global.launchArgs
    if (m.global.launchArgs <> invalid) then
        ' BRANCH SDK INTEGRATION - Call API'
        m.branchSdkObj.handleInput(m.global.launchArgs, "OnHandleInputCallbackFunc")
    else
        ShowMessageDialog("Please provide deepLinking arguments!")
    end if
end sub
      
function OnHandleInputCallbackFunc(event as object) as void
    data = event.GetData()
    print "OnHandleInputCallbackFunc: " data
    m.global.launchArgs = invalid
    message = "API Succeeded!"
    if (data.error <> invalid)
        message = "API Error!"
    end if
    ShowMessageDialog("handleInput" + " " + message)
end function

logEvent

Argument

类型

描述

name

String

Name of the event. List of compatible events can be found here.

customer_event_alias

String

The alias of your event.

transaction_id

String

The ID of of your event.

currency

String

The currency value of your event. List of compatible events can be found here.

revenue

String

The revenue of your event.

callbackFunc

String

Name of the callback function for your event.

用法示例

sub LogEventPurchase_Clicked()
    if (m.branchSdkObj = invalid) then
        ShowMessageDialog("Branch SDK is not initialized!")
        return
    end if

    print "Calling Branch LogEvent Standard API"
    ' BRANCH SDK INTEGRATION - Call API'
    m.branchSdkObj.logEvent(BranchSdkConstants().EVENT_TYPE.PURCHASE, "My First Purchase as customer_event_alias", "transaction_id", "INR", 99.99, "OnLogEventPurchaseCallbackFunc")
end sub

function OnLogEventPurchaseCallbackFunc(event as object) as void
    data = event.GetData()
    print "OnLogEventPurchaseCallbackFunc: " data
    message = "API Succeeded!"
    if (data.error <> invalid)
        message = "API Error!"
    end if
    ShowMessageDialog("logEvent Purchase" + " " + message)
end function

disableTracking

方法

描述

disableTracking: function(isDisable as boolean) as void

If you need to comply with a user's request to not be tracked for GDPR purposes, or otherwise determine that a user should not be tracked, utilize this field to prevent Branch from sending network requests.

Argument

类型

描述

isDisable

boolean

设置为 true to disable tracking. Set to false to enable tracking.

用法示例

sub init()
    m.bTracking.observeField("buttonSelected", "Tracking_Clicked")

    ' m.bInitSession.setFocus(true)'
    m.bSetIdentity.setFocus(true)

    ' BRANCH SDK INTEGRATION - Create Instance'
    m.branchSdkObj = CreateBranchSdkForSceneGraphApp()
end sub

sub Tracking_Clicked()
    if (m.branchSdkObj = invalid) then
        ShowMessageDialog("Branch SDK is not initialized!")
        return
    end if

    print "Calling Branch Tracking API"
    ' BRANCH SDK INTEGRATION - Call API'
    m.branchSdkObj.disableTracking(m.IsTracking)
    m.IsTracking = not m.IsTracking
    SetTrackingButtonText()
end sub

setIdentity

方法

描述

setIdentity: function(developer_identity = "", callbackFunc = "") as void

Sets the identity of the user. Typically performed when the user logs in.

Argument

类型

描述

developer_identity

String

The ID of the user logging in.

callbackFunc

String

Name of the callback function for setting identity.

用法示例

sub init()
    m.bSetIdentity.observeField("buttonSelected", "SetIdentity_Clicked")

    ' m.bInitSession.setFocus(true)'
    m.bSetIdentity.setFocus(true)

    ' BRANCH SDK INTEGRATION - Create Instance'
    m.branchSdkObj = CreateBranchSdkForSceneGraphApp()

    SetTrackingButtonText()
end sub

sub SetIdentity_Clicked()
    if (m.branchSdkObj = invalid) then
        ShowMessageDialog("Branch SDK is not initialized!")
        return
    end if

    print "Calling Branch SetIdentity API"
    ' BRANCH SDK INTEGRATION - Call API'
    m.branchSdkObj.setIdentity("User123", "OnSetIdentityCallbackFunc")
end sub

logout

方法

描述

logout: function(callbackFunc = "") as void

Removes the identity set from setIdentity. Typically used when the user logs out.

Argument

类型

描述

callbackFunc

String

Name of the callback function for removing identity.

用法示例

sub init()
    m.bLogout.observeField("buttonSelected", "Logout_Clicked")

    ' m.bInitSession.setFocus(true)'
    m.bSetIdentity.setFocus(true)

    ' BRANCH SDK INTEGRATION - Create Instance'
    m.branchSdkObj = CreateBranchSdkForSceneGraphApp()

    SetTrackingButtonText()
end sub

sub Logout_Clicked()
    if (m.branchSdkObj = invalid) then
        ShowMessageDialog("Branch SDK is not initialized!")
        return
    end if

    print "Calling Branch Logout API"
    ' BRANCH SDK INTEGRATION - Call API'
    m.branchSdkObj.logout("OnLogoutCallbackFunc")
end sub