Start by downloading the GitHub repository. Roku doesn't have a package manager, so you copy the implementation files from this repository to integrate Statsig in your Roku app.
source/Statsig: an object used by SceneGraph components that connects a StatsigClient with the background StatsigTask.
components/StatsigTask: a SceneGraph Task that runs in the background to batch events and fetch values from Statsig servers.
The components folder contains SceneGraph components and the source folder contains BrightScript files. All of these files must be included in their respective folders of the application. If you change the file paths, you must update the file references in StatsigTask.xml and include those references in your main XML file.
Initialize the SDK
Next, initialize the SDK with a client SDK key from the "API Keys" tab on the Statsig console. These keys are safe to embed in a client application.Along with the key, pass in a User Object with the attributes you'd like to target later on in a gate or experiment.
To initialize the SDK, first integrate the SDK files into your application.
Include StatsigClient.brs, StatsigUser.brs, DynamicConfig.brs, and Statsig.brs:
For more information on all of the user fields you can use, refer to the StatsigUser docs.
Before the SDK has loaded the updated values, all APIs will return default values (false for gates, empty configs and experiments).
To implement a callback handler for Statsig being ready, and tell the SDK to load the updated values in the onStatsigReady function observed above:
brightscript
function onStatsigReady() as void m.statsig.load() // Check gates, log events, check experiments, etc gate = m.statsig.checkGate("gate_id") config = m.statsig.getConfig("config_id") experiment = m.statsig.getExperiment("experiment_id") m.statsig.logEvent("event_name", "event_value", {metadata: "event_metadata"})end function
To update the user, m.statsig.updateUser(newUser) triggers the same onStatsigReady callback after the new gate/config/experiment values have been fetched from Statsig servers.