StableID
StableID is a concept in Statsig that allows us to have a consistent identifier for a single device. This allows Statsig to run experiments on logged out users (users without a UserID) as well as target gates on the device level rather than the user level.How it works
When you initialize the SDK for the first time, it checks if a StableID is already present in local storage. If it’s missing, the SDK generates a new StableID and saves it in local storage. On subsequent initializations, the SDK retrieves and reuses the previously stored StableID. The StableID is stored in local storage under the keystatsig.stable_id.<SDK_KEY_HASH>.
Each SDK key has its own StableID, meaning that if you’re using multiple SDK keys, each one will have a separate StableID.
It’s important to note that local storage is not shared across different domains or subdomains.
This means that if you are working across multiple domains or subdomains, the StableID will be isolated to each domain’s local storage.
If you need a StableID to persist across domains, you’ll need to implement your own mechanism to store and retrieve the StableID, such as using a cookie as demonstrated here.
The Statsig SDK does not use any cookies itself.
Accessing the StableID
You can access StableID that the Statsig client is using by callinggetContext() and then checking the stableID field.
- Javascript
- React
Overriding StableID
If your app already has something similar to a StableID and you would prefer to use that instead, you can override the default behavior by simply passing your value in as part of theStatsigUser object.
- Javascript
- React
Once overridden, the new StableID will be persisted to local storage so it will be used for future sessions.