Client Persistent Assignment
Persistent assignment allows you to ensure that a user's variant stays consistent while an experiment is running, regardless of changes to allocation or targeting.
Persistent Storage
The persistent storage adapter allows you to plug in your own storage solution that Statsig SDK uses to persist user assignments.
The user persistent storage interface consists of just a load
/loadAsync
, save
, delete
API for read/write operations.
info
Currently only supported in Javascript
, iOS
and Android
On Device Evaluation SDKs
Persistent Storage Logic
- Providing a storage adapter on Statsig initialization will give the SDK access to read & write on your custom storage
- Providing user persisted values to
get_experiment
will inform the SDK to- save the evaluation of the current user on first evaluation
- load the previously saved evaluation of a persisted user on subsequent evaluations
- delete the previously saved evaluation of a persisted user if the experiment is no longer active
- Not providing user persisted values to
get_experiment
will delete a previously saved evaluation
Example usage
- Javascript
- Javascript (legacy)
const storage = new CustomStorageAdapter(); // Need to implement
const adapter = new UserPersistentOverrideAdapter(storage);
const client = new StatsigOnDeviceEvalClient(
'client-key',
{ overrideAdapter: adapter }
);
await client.initializeAsync();
const userInControl = { userID: "123" }
const userInUnknown = { userID: "unknown" }
const userPersistedValues = adapter.loadUserPersistedValues(user, 'userID');
let experiment = client.getExperiment('active_experiment', user, { userPersistedValues });
console.log(experiment.getGroupName()) // 'Control'
experiment = client.getExperiment('active_experiment', userInUnknown, { userPersistedValues });
console.log(experiment.getGroupName()) // 'Control'
await statsig.initialize(
'client-key',
{ userPersistentStorage: new CustomStorageAdapter() } // Need to implement
);
const userInControl = { userID: "123" }
const userInUnknown = { userID: "unknown" }
const userPersistedValues = await statsig.loadUserPersistedValuesAsync(userInControl, 'userID');
let experiment = statsig.getExperiment(userInControl, 'active_experiment', { userPersistedValues });
console.log(experiment.getGroupName()) // 'Control'
experiment = statsig.getExperiment(userInUnknown, 'active_experiment', { userPersistedValues });
console.log(experiment.getGroupName()) // 'Control'