Skip to main content
@trevosdk/react-native runs experiments and records events in React Native and Expo apps, assigning the same variants the web SDK does for the same user. Pure TypeScript — no native module, no linking step, no config plugin. Expo:
Bare React Native:
AsyncStorage is a required peer, not an optional one. Without persistence the anonymous id is re-minted on every launch, which re-buckets every user and corrupts any running experiment.

Quick start

Create the client in its own module. This example uses Expo’s public environment convention; in bare React Native, use the app’s existing runtime-config adapter.
Keep the app’s existing splash/loading boundary visible while the hook returns null, so AsyncStorage hydration cannot flash control to a treatment user. If auth restores a known user, call trevo.identify(user.id) before mounting this experiment UI.
Use a Mobile key (tsk_live_…, created under API Keys). A shipped binary can be unpacked, so a secret key in an app is a leaked key. With a Mobile key, a shipped experiment stays in the config for a year, so old builds that still have its code keep getting the winner; a Web key drops it after 30 days.

Before your first mobile experiment

Mobile experiments ramp over weeks, wait for an app release, and keep running on old builds. Mobile experiments covers what that means for planning, how the SDK survives a lost network or a killed app, and the App Store and Google Play answers.

Gating on app version

An experiment whose variant code only exists from a given build onward should not enrol devices that cannot render it. Set minAppVersion on the experiment:
Builds below the threshold get control and record no exposure, so they never appear in the results. This requires you to pass appVersion when creating the client — without it, a gated experiment returns control for everyone, because the SDK cannot prove the build is new enough and guessing wrong means a broken screen. Always pass the installed binary’s real app version, never a copied sample. Expo apps can read it from expo-application (npx expo install expo-application):
For bare React Native, pass the value from the build-metadata adapter the app already uses; do not hard-code it. Every event also records it, so each event names the build that sent it.

Options

API summary

Expo

Works in Expo Go and in development builds with no config plugin — there is no native code to link. Install AsyncStorage the Expo way:

Store compliance

The package ships ios/PrivacyInfo.xcprivacy. The Google Play data safety answers are in Mobile experiments.

Correctness

This package runs the shared conformance vectors against its public API in CI, so a change that would bucket a user differently from the browser fails the build. The normative rules are in the bucketing spec.