Skip to main content
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

Persistent storage takes an “adapter” approach, allowing you to plug in a storage solution of your choice to store assignments, which can then be referenced later to ensure a user stays in the same bucket. You can implement an adapter that uses Local Storage, or one that uses remote storage, to enable persistence across multiple devices. The user persistent storage interface consists of just a load/loadAsync, save, delete API for read/write operations.
Persistent Storage is currently supported on:

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

Support in iOS and Android SDKs

Android and iOS SDKs offer a simplified version of Persistent Storage called keepDeviceValues that relies on on-device storage. While this is less flexible its simple to leverage - with a simple boolean flag. When enabled, the SDK (under the hood in the getExperiment/getLayer call) will check for previous stored value, and use those instead, even if allocation or targeting has changed. When the experiment ends - the SDK will stop persisting values.

Swift:

Objective C: