Skip to main content
Official GrowthBook SDK for Roku/js applications. Add feature flags and A/B testing to your Roku channels with a simple, lightweight SDK.

Platform Requirements

The GrowthBook SDK supports all modern Roku devices and OS versions:
  • Minimum OS Version: Roku OS 9.0+
  • Recommended: Roku OS 9.2+ (for AES encryption support)
  • Tested on: Roku OS 9.0 - 12.x
Device Compatibility:
  • ✅ Roku Ultra (all versions)
  • ✅ Roku Streaming Stick (all versions)
  • ✅ Roku Express
  • ✅ Roku Premiere
  • ✅ Roku TV
  • ✅ Legacy devices (Roku 2, Roku 3)

Installation

  1. Download GrowthBook.brs from the GitHub repository.
  2. Copy it to your channel’s source/ directory:

Installation with ropm

If you are using ropm for dependency management:

Quick Usage

Step 1: Initialize the SDK

Initialize GrowthBook once when your channel starts. Use a singleton pattern to reuse the instance throughout your app.

Step 2: Use Feature Flags

Once initialized, access the GrowthBook instance anywhere in your channel:

Loading Features

The GrowthBook SDK provides multiple strategies for loading feature flags, allowing you to choose between automated feature loading at the init or using it in offline mode.

Automated Loading

At the time of initialization, the SDK automatically fetches features from the GrowthBook API when you provide apiHost and clientKey:
How It Works:
  1. When init() is called, the SDK makes an HTTP request to {apiHost}/api/features/{clientKey}
  2. Features are cached in memory for the lifetime of the instance
  3. All subsequent feature evaluations use the cached data (no additional network calls)
Feature Refresh Frequency:
  • Features are loaded once when init() is called
  • No automatic background refresh is supported for now.
  • Roku Limitation: Unlike web SDKs, Roku does not support Server-Sent Events (SSE) for real-time streaming updates
  • To get updated features, you must reinitialize the GrowthBook instance (typically on app restart)
  • For real-time updates, implement a manual refresh mechanism:

Offline Mode

For scenarios where network access is unavailable or you want to embed features directly in your channel, use offline mode.
When to Use Offline Mode:
  • ✅ Testing and development without GrowthBook account
  • ✅ Regions with unreliable or no network connectivity
  • ✅ Regulatory requirements preventing external API calls
  • ✅ Feature flags that rarely change and can be bundled with app
  • ✅ Fallback strategy for network failures
  • ✅ Kiosk or offline-first applications
Limitations:
  • ❌ Features must be updated via channel deployment (sideload or store update)
  • ❌ Cannot change feature values remotely without app update
  • ❌ No real-time experimentation updates

Configuration Options

Required Options

At minimum, provide either clientKey OR features:

All Configuration Options

Instance Management (Singleton Pattern)

Recommended: Create one instance and reuse it globally.
Creating multiple GrowthBook instances causes problems:

Updating Attributes

Update user attributes without recreating the instance:

Feature Flags

There are 2 main methods for evaluating features: isOn and getFeatureValue:

Boolean Flags

Simple on/off toggles:

Feature Values

Get configuration values with type-safe fallbacks:

JSON Configuration

Complex objects for advanced configuration:

Experimentation (A/B Testing)

There is nothing special you have to do for feature flag experiments. Just evaluate the feature flag like you would normally do. If the user is put into an experiment as part of the feature flag, it will call the trackingCallback automatically in the background.

Tracking Callbacks

GrowthBook provides two types of callbacks to monitor feature usage and experiment exposure:

Experiment Tracking Callback

The trackingCallback is fired when a user is placed into an experiment. Use this to send experiment exposure events to your analytics platform (Segment, Mixpanel, Google Analytics, etc.).
Callback Parameters: experiment object:
  • key (string) - Experiment identifier
  • variations (array) - List of possible variations
  • weights (array) - Traffic allocation weights
  • hashVersion (integer) - Hash algorithm version
  • namespace (array) - Namespace for traffic allocation
result object:
  • experimentId (string) - Experiment key
  • variationId (integer) - Assigned variation index (0-based)
  • value (dynamic) - Actual variation value
  • ruleId (string) - ID of the rule that triggered
  • source (string) - Always "experiment" for tracking callback
  • on (boolean) - Whether feature is enabled
  • key (string) - Feature key
When It Fires:
  • User enters an experiment (assigned to a variation)
  • Only fires ONCE per unique experiment + user combination (de-duplicated)
Does NOT fire for:
  • Features with no experiments
  • Users excluded from experiments
  • Forced variations

Feature Usage Callback

The onFeatureUsage callback is fired on every feature evaluation, not just experiments. Use this for high-level usage tracking or debugging.
Callback Parameters:
  • featureKey (string) - The key of the feature being evaluated
  • result (object) - Complete evaluation result (same structure as evalFeature())
When It Fires:
  • Every call to isOn(), getFeatureValue(), or evalFeature()
  • Includes all sources: "defaultValue", "force", "experiment", "unknownFeature"

Comparison

Hashing and Consistent Assignment

GrowthBook uses deterministic hashing to ensure users get consistent variation assignments. This is critical for accurate A/B testing.

How Hashing Works

When a user is evaluated for an experiment:
  1. Hash Input: The SDK combines the user’s id attribute with the experiment key
  2. Generate Hash: Uses FNV-1a hashing algorithm to produce a number between 0 and 1
  3. Map to Bucket: The hash maps to a specific variation based on traffic weights
  4. Return Variation: User is assigned to that variation consistently

Hash Attribute

By default, GrowthBook uses the id attribute for hashing. You can customize which attribute to use with the hashAttribute setting in your experiment rules. Default Behavior:
Custom Hash Attribute: In the GrowthBook dashboard, set hashAttribute in your experiment rule:

When to Use Custom Hash Attributes

Use custom hash attributes when: Example: Device-Level Experiment

Debugging Hash Assignments

Enable dev mode to see hash calculations:

Production Best Practices

Error Handling

Always check if GrowthBook initialized successfully:

Performance Optimization

Avoid calling feature checks in tight loops:

Troubleshooting

1) SDK Not Loading

GrowthBook() returns invalid
  1. Verify GrowthBook.brs is in source/ directory
  2. Check file name is exactly GrowthBook.brs (case-sensitive)
  3. Ensure no syntax errors in the file
  4. Try compiling channel to see errors

2) Features Not Loading

init() returns false
  1. Check clientKey is correct
  2. Verify network connectivity
  3. Test API endpoint: https://cdn.growthbook.io/api/features/YOUR_KEY
  4. Enable dev mode: enableDevMode: true to see error logs
  5. Provide fallback features for offline resilience

3) Version Targeting Not Working

Version-based rules don’t match
  1. Use semantic versioning: "2.1.0" not "2.1" or "v2.1.0"
  2. Verify appVersion attribute is set correctly
  3. Test version operators in GrowthBook dashboard preview
  4. Enable dev mode to see evaluation logs

4) Inconsistent Variations

User sees different variations across sessions
  1. Ensure id attribute is stable (use device ID, not random)
  2. Don’t use Rnd() or random values for id
  3. Verify id is set before evaluating features
  4. Check that you’re not creating multiple GrowthBook instances

5) Experiments Show Wrong Traffic Split

50/50 split when expecting 70/30
  1. Verify weights in GrowthBook dashboard match expectations
  2. Ensure weights array length matches variations count
  3. Test with multiple user IDs to verify distribution
  4. Check experiment is published and active

Limitations

  • ❌ No Server-Sent Events (SSE) streaming support (Roku limitation)
  • ❌ No Visual Editor experiments (SceneGraph only)
  • ❌ AES decryption requires Roku OS 9.2+ (roEVPCipher component)
  • ❌ Network requests are asynchronous only (no sync API)

Supported Features