Roku — 使用 SceneGraph 進行追蹤 tracking-in-scenegraph-roku
簡介 introduction
您可以使用 Roku SceneGraph XML 程式設計架構來開發應用程式。此架構有兩個的重要概念:
- SceneGraph 演算應用程式畫面
- SceneGraph 畫面的 XML 設定
Adobe Mobile SDK for Roku 是以 BrightScript 編寫。此 SDK 有許多元件不適用於 SceneGraph 上執行的應用程式 (如執行緒)。因此,想使用 SceneGraph 架構的 Roku 應用程式開發人員,無法呼叫 Adobe Mobile SDK API (後者類似於舊版 BrightScript 應用程式中的 API)。
架構 architecture
為了將 SceneGraph 支援加入 AdobeMobile SDK,Adobe 已新增一個新的 API,該 API 在 AdobeMobile SDK 和 adbmobileTask
之間建立連接器橋接器。後者是用於 SDK 之 API 執行的 SceneGraph 節點。(在本文件其他章節中詳細說明 adbmobileTask
的用法。)
連接器橋接器專為執行下列功能所設計:
- 橋接器會傳回 Adobe Mobile SDK 與 SceneGraph 相容的執行個體。與 SceneGraph 相容的 SDK 包含舊版 SDK 揭露的所有 API。
- 您在 SceneGraph 中使用 Adobe Mobile SDK API 的方式,與使用舊版 API 的方式非常類似。
- 橋接器也會揭露機制,監聽傳回部分資料的 API 回呼。
元件 components
SceneGraph 應用程式:
- 透過 SceneGraph 連接器橋接器 API 使用
AdobeMobileLibrary
API。 - 針對預期的輸出資料變數在
adbmobileTask
上註冊回應回呼。
AdobeMobileLibrary:
- 揭露一組公用 API (舊版),包括連接器橋接器 API。
- 傳回納入所有舊版公用 API 的 SceneGraph 連接器執行個體。
- 與
adbmobileTask
SceneGraph 節點通訊以執行 API。
adbmobileTask 節點:
- 在背景執行緒上執行
AdobeMobileLibrary
API 的 SceneGraph 任務節點。 - 作為委派以將資料傳回應用程式場景。
公用 SceneGraph API public-scenegraph-apis
ADBMobileConnector
sceneGraphConstants
SceneGraphConstants
的物件。如需詳細資料,請參閱上表。setDebugLogging
getDebugLogging
setPrivacyStatus
getPrivacyStatus
trackState
trackAction
trackingIdentifier
userIdentifier
setUserIdentifier
getAllIdentifiers
visitorSyncIdentifiers
visitorMarketingCloudID
audienceSubmitSignal
audienceVisitorProfile
audienceDpid
audienceDpuuid
audienceSetDpidAndDpuuid
mediaTrackLoad
mediaTrackUnload
mediaTrackPlay
mediaTrackComplete
mediaTrackError
mediaUpdatePlayhead
mediaUpdateQoS
SceneGraphConstants
API_RESPONSE
adbmobileTask
節點的 adbmobileApiResponse
欄位擷取回應物件DEBUG_LOGGING
getDebugLogging
的 apiName
PRIVACY_STATUS
getPrivacyStatus
的 apiName
TRACKING_IDENTIFIER
trackingIdentifier
的 apiName
USER_IDENTIFIER
userIdentifier
的 apiName
VISITOR_MARKETING_CLOUD_ID
visitorMarketingCloudID
的 apiName
AUDIENCE_VISITOR_PROFILE
audienceVisitorProfile
的 apiName
AUDIENCE_DPID
audienceDpid
的 apiName
AUDIENCE_DPUUID
audienceDpuuid
的 apiName
adbmobileTask 節點
唯讀:在 AdobeMobileSDK 上執行的所有 API 將在此欄位上傳回回應。登錄回呼以監聽此欄位的更新,以接收回應物件。回應物件的格式如下:
response = {
"apiName" :<SceneGraphConstants.
API_NAME>
"returnValue : <API_RESPONSE>
}
此回應物件的例項將在 AdobeMobileSDK 上針對任何 API 呼叫傳送,預計該 API 呼叫會根據 API 參考指南傳回值。例如,visitorMarketingCloudID() 的 API 呼叫將傳回以下回應物件:
response = {
"apiName" :m.
adbmobileConstants.
VISITOR_MARKETING_CLOUD_ID
"returnValue : "07050x25671x33760x72644x14"
}
或者,回應資料也可能無效:
response = {
"apiName" :m.
adbmobileConstants.
VISITOR_MARKETING_CLOUD_ID
"returnValue : invalid
}
adbmobile.brs
getADBMobileConnectorInstance
API 簽章:ADBMobile().getADBMobileConnectorInstance()
輸入:adbmobileTask
傳回類型:ADBMobileConnector
sgConstants
API 簽章:ADBMobile().sgConstants()
輸入:無
傳回類型:SceneGraphConstants
ADBMobileConnector
API 參考資料。ADBMobile 常數
version
PRIVACY_STATUS_OPT_IN
PRIVACY_STATUS_OPT_OUT
傳統 AdobeMobileLibrary 上全域定義之公用程式 MediaHeartbeat
API 的存取方式 如同 在 SceneGraph 環境中存取一樣,因為這些 API 未使用任何在 SceneGraph 節點中無法使用的 Brightscript 元件。如需這些方法的詳細資訊,請參閱下表:
適用於 MediaHeartbeat 的全域方法
adb_media_init_mediainfo
Function adb_media_init_mediainfo(name As String, id As String, length As Double, streamType As String) As Object
adb_media_init_adinfo
Function adb_media_init_adinfo(name As String, id As String, position As Double, length As Double) As Object
adb_media_init_chapterinfo
Function adb_media_init_adbreakinfo(name As String, startTime as Double, position as Double) As Object
adb_media_init_adbreakinfo
Function adb_media_init_chapterinfo(name As String, position As Double, length As Double, startTime As Double) As Object
adb_media_init_qosinfo
Function adb_media_init_qosinfo(bitrate As Double, startupTime as Double, fps as Double, droppedFrames as Double) As Object
實作 implementation
-
下載 Roku 程式庫 - 下載最新 Roku 程式庫。
-
設定您的開發環境
-
將
adbmobile.brs
(AdobeMobileLibrary) 複製至您的pkg:/source/
目錄。 -
如需「場景圖形」支援,請將
adbmobileTask.brs
和adbMobileTask.xml
複製至您的pkg:/components/
目錄。
-
-
初始化
-
將
adbmobile.brs
匯入您的「場景」。code language-none <script type="text/brightscript" uri="pkg:/source/adbmobile.brs" />
-
將
adbmobileTask
節點例項建立在您的場景中。code language-none m.adbmobileTask = createObject("roSGNode", "adbmobileTask")
-
使用
adbmobile
例項取得 SceneGraph 適用的instance ofadbmobileTask
連接器例項。code language-none m.adbmobile = ADBMobile().getADBMobileConnectorInstance(m.adbmobileTask)
-
取得
adbmobile
SG 常數。code language-none m.adbmobileConstants = m.adbmobile.sceneGraphConstants()
-
註冊回撥以便為所有
AdbMobile
API 呼叫接收回應物件。code language-none m.adbmobileTask.ObserveField(m.adbmobileConstants.API_RESPONSE, "onAdbmobileApiResponse") ' Sample implementation of the callback ' Listen for all the constants for which API calls are made on the SDK function onAdbmobileApiResponse() as void responseObject = m.adbmobileTask[m.adbmobileConstants.API_RESPONSE] if responseObject <> invalid methodName = responseObject.apiName retVal = responseObject.returnValue if methodName = m.adbmobileConstants.DEBUG_LOGGING if retVal print "API Response: DEBUG LOGGING: " + "True" else print "API Response: DEBUG LOGGING: " + "False" endif else if methodName = m.adbmobileConstants.PRIVACY_STATUS print "API Response: PRIVACY STATUS: " + retVal else if methodName = m.adbmobileConstants.TRACKING_IDENTIFIER if retVal <> invalid print "API Response: TRACKING IDENTIFIER: " + retVal else print "API Response: TRACKING IDENTIFIER: " + "invalid" endif else if methodName = m.adbmobileConstants.USER_IDENTIFIER if retVal <> invalid print "API Response: USER IDENTIFIER: " + retVal else print "API Response: USER IDENTIFIER: " + "invalid" endif else if methodName = m.adbmobileConstants.VISITOR_MARKETING_CLOUD_ID if retVal <> invalid print "API Response: MCID: " + retVal else print "API Response: MCID: " + "invalid" endif else if methodName = m.adbmobileConstants.AUDIENCE_DPID if retVal <> invalid print "API Response: AUDIENCE DPID: " + retVal else print "API Response: AUDIENCE DPID: " + "invalid" endif else if methodName = m.adbmobileConstants.AUDIENCE_DPUUID if retVal <> invalid print "API Response: AUDIENCE DPUUID: " + retVal else print "API Response: AUDIENCE DPUUID: " + "invalid" endif else if methodName = m.adbmobileConstants.AUDIENCE_VISITOR_PROFILE if retVal <> invalid print "API Response: AUDIENCE VISITOR PROFILE: Valid Object" else print "API Response: AUDIENCE VISITOR PROFILE: " + "invalid" endif endif endif end function
-
實作範例 sample-implementation
舊版 SDK 上的 API 呼叫範例
'get an instance of SDK
m.adbmobile = ADBMobile()
'execute setter APIs
m.adbmobile.setDebugLogging(true)
'execute getter APIs
debugLogging = m.adbmobile.getDebugLogging()
SG SDK 上的 API 呼叫範例
'create adbmobileTask instance
m.adbmobileTask = createObject("roSGNode", "adbmobileTask")
'get an instance of SDK using task instance
m.adbmobile =
ADBMobile().getADBMobileConnectorInstace(m.adbmobileTask)
m.adbmobileConstants = m.adbmobile.sceneGraphConstants()
'execute setter APIs
m.adbmobile.setDebugLogging(true)
'execute getter APIs
m.adbmobileTask.ObserverField(m.adbConstants.API_RESPONSE,
"onAdbmobileApiResponse")
m.adbmobile.getDebugLogging()
'listen for return data in registered callbacks
function onAdbmobileApiResponse() as void
responseObject = m.adbmobileTask[m.adbmobileConstants.API_RESPONSE]
if responseObject <> invalid
methodName = responseObject.apiName
retVal = responseObject.returnValue
if methodName = m.adbmobileConstants.DEBUG_LOGGING
if retVal
print "API Response: DEBUG LOGGING: " + "True"
else
print "API Response: DEBUG LOGGING: " + "False"
endif
endif
end function