Why identify users?
When you run an experiment, rollout a feature, or log events, Statsig needs to know who the user is to determine:- Targeting: whether a feature gate should pass or fail for a given user
- Experiment bucketing: which group a user belongs to
- Analytics: How many unique users triggered an event
Basic User Object
Start by defining a basic user object:Identifying users in Client SDKs
In client SDKs, the SDK is “initialized” for a single User Object at any one time. If you try to call a method like checkGate or getExperiment before your SDK is initialized, you won’t get expected results - and you’ll see warnings in the Statsig Console when you look at the diagnostics tab of any gate or experiment. Initialization requires a network request, which you fire by calling theinitialize() method, or in React, useClientAsyncInit().
This means that in client apps with asynchronous logic, you’ll want to wait for initialization to complete before you check a gate. For example, in React:
userID) then you’ll need to call the updateUser method, which calls to the Statsig Server to refresh the values. For example, in React:
email, companyID, or other attributes - add them to your User object.
Identifying users in Server SDKs
In Server SDKs, you pass a User Object with each evaluation or event call such as logEvent, checkGate or getFeatureGate. The Server SDK holds the necessary rules in memory to enable correct evaluation. Every time you call one of these methods - you should pass all of the attributes needed to evaluate your gate or experiment. The Statsig SDKs don’t “remember” or enrich previous attributes seen. Example (Node.js)Enriched attributes
Statsig attempts to enrich the user object with useful attributes to give you more targeting power. Examples of what Statsig can enrich for you:stableID: an anonymous identifier which identifies a unique device on client SDKscountry: derived from IP or device localeappVersion: pulled from mobile SDKsbrowser/OS: captured from user agent- and more…
custom attributes, customIDs, and privateAttributes — see the StatsigUser object docs.