Skip to main content

Introduction to the StatsigUser object

The user(StatsigUser) object is the sole input you provide to SDKs to target gates and assign users to experiments. If you’d like to target on an attribute, you’ll need to add it to your user object, so assembling the data is an important part of SDK setup. We recommend providing as much info as practical, as every additional field can enrich your analyses and expand targeting possibilities. Statsig also infers some information about each user based on other traits (for example, we resolve IP Addresses into countries), read on for more details.

Usage Example in Node:

I passed that attribute before - why do I need to pass it again?

If you want to see a specific user’s historical attributes for analytics purposes, you can see that in the statsig console via User Profiles. However, you cannot use a user’s historical attributes for targeting or gate/experiment evaluation at runtime. Statsig evaluates gates and experiment buckets based only on the information you provide when you check something. Statsig’s promise of evaluating every gate or experiment in milliseconds is dependent on having all information available at request time, rather than querying previous data, or storing massive amounts of historical data in memory.

User Attributes

All user attributes can be explicitly supplied, and some can be inferred from a user’s device or connection. Supplying one will always override an inferred value.

Have sensitive user PII data that should not be logged?

On the StatsigUser object, there is a field called privateAttributes, which is a simple object/dictionary that you can use to set private user attributes. Any attribute set in privateAttributes will only be used for evaluation/targeting, and removed from any logs before they are sent to Statsig server. For example, if you have feature gates that should only pass for users with emails ending in “@statsig.com”, but do not want to log your users’ email addresses to Statsig, you can simply add the key-value pair { email: "my_user@statsig.com" } to privateAttributes on the user and that’s it!

Time-based conditions

All SDKs (both server and client-side) support unix timestamps in milliseconds to evaluate time based conditions (After time, before time). Without knowing all possible variations of DateTime formats, we have to normalize on something, so its best to convert your DateTime field into a standard format for evaluation. We have added support for ISO timestamps to some server SDKs. We have added support for ISO timestamps to server SDKs supported by server core (Java, Python, PHP, Rust, Node).

Why is an ID always required for server SDKs?

In Server SDKs, a StatsigUser with a userID (or customID) is required for checkGate, getConfig, and getExperiment. In short, its always better to pass the user ID if it’s available: users will get a stable experience, and any events will be attributed to the correct users so you can accurately measure downstream metrics. Still don’t want to pass an ID? Here are our suggestions for different use cases:
  1. If you plan to only use one/off feature gates, or non-percent-based rules (like countries) While you’re still losing functionality, you can pass any non-empty identifier, hard coded string, or a random ID less than 100 if you do not have the actual user ID. Don’t pass a purely random ID - as we won’t be able to dedupe your events, you’ll explode your event usage, and your Statsig bill.
  2. If you want to rollout a feature partially, check for regressions, then roll out to everyone, you must pass an ID in your checkGate/getConfig/getExperiment calls, as well as any logEvent calls you make. Otherwise, we’re not able to attribute the events you log to the correct users who saw or didn’t see your new feature, or calculate metrics correctly to help you see any regressions.
  3. If you want to run an A/B experiment to decide whether to ship a new feature, you should also pass the persistent user IDs, for the same reason mentioned in 2, above.
  4. If you want to pass a userID for the above reasons, but don’t have a logged in user (e.g. you are optimizing the login flow), set a stable identifier (we provide one in client SDKs!) as a cookie or in local storage and use that with each call to Statsig.
We hope this is helpful. If you have a use case that is not covered in these scenarios, or have any question at all, feel free to join our Slack community and drop a question/comment there!

Pass all IDs when you have them

A common mistake is to accidentally expose users without a userID to a user-ID based experiment. All of them will be bucketed into one group (whichever the “null” userID goes to), polluting your results. If you run experiments on multiple ID types (or you might one day), its best to pass every identifier available.