Tip: Get started quickly with one of our sample apps!
Source code: statsig-io/js-client-monorepo
Statsig’s normal (remote evaluation) SDKs are recommended for most client applications. Understand the use case and privacy risks by reading the On-Device Eval SDK overview. On-device evaluation SDKs are for Enterprise & Pro Tier only.
Pros
- No need for a network request when changing user properties - just check the gate/config/experiment locally
- Can bring your own CDN or synchronously initialize with a preloaded project definition
- Lower latency to download configs cached at the edge, rather than evaluated for a given user (which cannot be cached as much)
Cons
- Entire project definition is available client side - the names and configurations of all experiments and feature flags accessible by your client key are exposed. See our client key with server permission best practices
- Payload size is strictly larger than what is required for the traditional SDKs
- Evaluation performance is slightly slower - rather than looking up the value, the SDK must actually evaluate targeting conditions and an allocation decision
- Does not support ID list segments with > 1000 IDs
- Does not support IP or User Agent based checks (Browser Version/Name, OS Version/Name, IP, Country)
Since
@statsig/react-native-bindings-on-device-eval
works in conjunction with @statsig/js-on-device-eval-client
, documentation on the JavaScript On-Device Evaluation SDK is also relevant for React Native implementations.Set Up the SDK
1
Install the SDK
Installation
Since the
@statsig/react-native-bindings-on-device-eval
works in conjunction with @statsig/js-on-device-eval-client
, documentation on those packages is also relevant for React Native implementations.Peer Dependencies
The@statsig/react-native-bindings-on-device-eval
package has peer dependencies which may also need to be installed if they are not already in your project.2
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.
For On-Device Evaluation, you’ll need to add the “Allow Download Config Specs” scope. Client keys, by default, are not able to download the project definition for on-device evaluation.While client keys are safe to include, Server and Console keys should always be kept private.
How to add the scope
How to add the scope
- New SDK Keys
- Existing SDK Keys
When creating a new client key, select “Allow Download Config Specs”

React Native Specific Setup
To get setup with Statsig in a React Native component tree, you should use the RN specificStatsigProviderOnDeviceEvalRN
. This automatically switches out the storage layer used by the SDK, utilizing AsyncStorage instead of LocalStorage (which isn’t available in RN environments).Working with the SDK
Setup a StatsigUser
To interact with the SDK, you will need to create aStatsigUser
object. The full definition of this
object can be found here.
React Hooks
useGateValue or useFeatureGate
useDynamicConfig
useExperiment
useLayer
Code Examples
Working sample apps are available in the repository:Statsig User
You need to provide a StatsigUser object to check/get your configurations. You should pass as much information as possible in order to take advantage of advanced gate and config conditions. Most of the time, theuserID
field is needed in order to provide a consistent experience for a given
user (see logged-out experiments to understand how to correctly run experiments for logged-out
users).
Besides userID
, we also have email
, ip
, userAgent
, country
, locale
and appVersion
as top-level fields on
StatsigUser. In addition, you can pass any key-value pairs in an object/dictionary to the custom
field and be able to
create targeting based on them.
Once the user logs in or has an update/changed, make sure to call updateUser
with the updated userID
and/or any other updated user attributes:
For the React Native On-Device Evaluation SDK, you pass the `StatsigUser` object directly into each evaluation method (`checkGate`, `getConfig`, etc.) rather than during initialization.
Unlike precomputed evaluation SDKs, the on-device evaluation SDK does not have an `updateUser` method since it evaluates gates/configs/experiments in real-time for any user object you pass in.
Client Event Emitter
It is possible to subscribe to StatsigClientEvents (Not to be confused with StatsigEvent). These events occur at various stages while using the Statsig client. You can subscribe to specific events by specifying the StatsigClientEvent name, or, all events by using the wildcard token'*'
.
Statsig Options
You can configure certain aspects of the SDKs behavior by passing a StatsigOptions object during initialization.The API to use for all SDK network requests. You should not need to override this unless you have another API that implements the Statsig API endpoints.
The URL used to flush queued events via a POST request. Takes precedence over
StatsigOptions.api
.The URL used to flush queued events via
window.navigator.sendBeacon
(web only). Takes precedence over StatsigOptions.api
.The URL used to fetch your latest Statsig specifications. Takes precedence over
StatsigOptions.api
.An object you can use to set environment variables that apply to all of your users in the same session.
Overrides the auto-generated stableID that is set for the device.
How much information is allowed to be printed to the console.
Implementing this type allows customization of the initialization. See Using SpecsDataAdapter to learn more.
The maximum amount of time (in milliseconds) that any network request can take before timing out.
The maximum number of events to batch before flushing logs to Statsig.
How often (in milliseconds) to flush logs to Statsig.
An implementor of
OverrideAdapter
, used to alter evaluations before its returned to the caller of a check api (checkGate/getExperiment etc).Manual Exposures
Manual logging is error-prone and can often introduce issues like uneven exposures, which compromise experiment results.
Gates
Configs
Experiments
Layers
Lifecycle & Advanced Usage
Shutting Statsig Down
In order to save users’ data and battery usage, as well as prevent logged events from being dropped, we keep event logs in client cache and flush periodically. Because of this, some events may not have been sent when your app shuts down. To make sure all logged events are properly flushed or saved locally, you should tell Statsig to shutdown when your app is closing:Data Adapter
TheEvaluationsDataAdapter
type outlines how the StatsigClient
should fetch and cache data during initialize and update operations.
By default, the StatsigClient
uses StatsigEvaluationsDataAdapter
, a Statsig provided implementor of the EvaluationsDataAdapter
type. StatsigEvaluationsDataAdapter
provides ways to fetch data synchronously from Local Storage and asynchronously from Statsig’s servers.
See Using EvaluationsDataAdapter to learn more and see example usage.