Skip to main content

Run experiments

Version:

The justtrack SDK lets you run server-side experiments (A/B tests) in your app. Experiments are configured on the justtrack backend, which assigns each user to a variant. The SDK fetches these assignments and gives you typed access to config values so you can branch your app logic accordingly.

In this guide, you'll learn to:

  • Fetch experiment assignments from the server
  • Activate experiments to confirm user enrollment
  • Read experiment values in your app
  • Configure the fetch interval

Fetch experiment assignments

Call fetch to pull the latest experiment assignments from the justtrack backend. The SDK caches assignments locally, so subsequent reads are fast and offline-safe.

For example, on app launch you'd fetch the latest assignments so your UI reflects the user's assigned variants:

await JustTrackSdk.remoteConfig.fetch();
info

The SDK respects a minimum fetch interval to avoid excessive network requests. If you call fetch again before the interval has elapsed, the SDK returns the cached assignments without contacting the server. See Configure the fetch interval for details.

Activate experiments

Fetching assignments downloads them to the device, but doesn't tell the backend the user was actually exposed to the experiment. Call activate to confirm enrollment — only activated experiments count toward your experiment results in the dashboard.

For example, after the user sees a new onboarding flow, activate that experiment so justtrack records the exposure:

const assignments = JustTrackSdk.remoteConfig.getAll();
const experimentIds = assignments.map(a => a.experimentId);
await JustTrackSdk.remoteConfig.activate(experimentIds);

Fetch and activate in one step

If you want to fetch the latest assignments and immediately confirm enrollment for all of them, use fetchAndActivate. This is useful at app startup when you want to get everything ready in a single call:

await JustTrackSdk.remoteConfig.fetchAndActivate();

Read experiment values

After fetching, you can read experiment values from the local cache. Values are available immediately and don't require a network call.

Get all assignments

To list every experiment the user is enrolled in, call getAll. Each assignment contains the config key, its value, the experiment ID, and whether it's still pending activation.

This is useful for building a debug screen or iterating over all active experiments:

const assignments = JustTrackSdk.remoteConfig.getAll();
assignments.forEach(a => {
console.log(`${a.configKey} = ${a.configValue}`);
});

Each assignment has the following fields:

FieldDescription
configKeyThe key you use to look up this value (e.g. "onboarding_variant").
configValueThe raw string value assigned to this user.
experimentIdThe unique ID of the experiment this assignment belongs to.
isPendingtrue if the assignment hasn't been activated yet.

Get a value by config key

To check a specific experiment value, use one of the typed getter methods. For example, to decide which onboarding flow to show:

const variant = JustTrackSdk.remoteConfig.getString('onboarding_variant');
if (variant === 'new_flow') {
showNewOnboarding();
} else {
showDefaultOnboarding();
}

The following typed getters are available:

TypeAndroidiOSUnityReact Native
StringgetString()getString()GetString()getString()
BooleangetBoolean()getBool()GetBoolean()getBoolean()
IntegergetInt()getInt()GetInt()getNumber()
DoublegetDouble()getDouble()GetDouble()getNumber()
LonggetLong()GetLong()

All getters return null if no assignment exists for the given config key.

Configure the fetch interval

The SDK enforces a minimum interval between server fetches to avoid unnecessary network requests. If you call fetch before the interval has elapsed, the SDK returns cached assignments instead.

The default interval is 24 hours (86,400 seconds).

During development, you can lower this interval to iterate faster:

JustTrackSdk.remoteConfig.setConfig({ minFetchIntervalInSeconds: 60 });
warning

Keep the default interval in production. Lowering it causes more network requests from every user, which increases load on your app and the justtrack backend.

Example: A/B test your onboarding flow

Here's a complete example that ties everything together. Suppose you've configured an experiment on the justtrack backend with a config key onboarding_variant. Users are assigned either "control" (the existing flow) or "new_flow" (a redesigned experience).

At app startup, fetch and activate the experiment, then branch your logic based on the assigned variant:

// Fetch the latest experiment assignments and activate them
await JustTrackSdk.remoteConfig.fetchAndActivate();

// Read the assigned variant
const variant = JustTrackSdk.remoteConfig.getString('onboarding_variant');

if (variant === 'new_flow') {
showNewOnboarding();
} else {
showDefaultOnboarding();
}