Skip to main content

StatsigUser Object

Introduction

You should provide a StatsigUser object whenever possible when initializing the SDK, passing as much information as possible in order to take advantage of advanced gate and config conditions (like country or OS/browser level checks). Most of the time, the User ID field is needed in order to provide a consistent experience for a given user (see device-level experiments to understand how to correctly run experiments for logged-out users). If the user is logged out at the SDK init time, you can leave out the User ID field, and Statsig will use a stable device ID that the SDK creates and stores in the local storage for targeting purposes.

User Attributes

AttributesDescriptionKeyExample
User IDID representing a unique user. This ID will be used to guarantee consistency of targeting for Feature Gates and Experiments and will be used to evaluate experiment results. If User ID doesn't exist yet, leave this empty; a Stable ID persisted locally will be used for evaluations.userIDyour_user_id
EmailEmail of the useremailmarcos@statsig.com
User AgentUser agent of the browser. This will be decoded to determine the Browser and Operating System of the user's context. Will be inferred if not provideduserAgentMozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.40 Safari/537.36
IPIP address of the user. Will be inferred if not providedip192.168.1.101
Country2 letter coutry code of the user. Will be inferred if not providedcountryUS
LocaleLocale of the user. When using the Android or iOS SDK, will be inferred if not providedlocaleen_US
App VersionVersion of the app the user is using. When using the Android or iOS SDK, will be inferred if not providedappVersion1.0.1
Operating SystemWhen using our client SDK, this will be automatically assigned, but you can also provide an explicit operating system to overridesystemNameAndroid
Operating System VersionWhen using our client SDK, this will be automatically assigned, but you can also provide an explicit OS version to overridesystemVersion15.4
Browser NameWhen using our client SDK, this will be automatically assigned, but you can also provide an explicit Browser Name to overridebrowserNameChrome
Browser VersonWhen using our client SDK, this will be automatically assigned, but you can also provide an explicit Browser Version to overridebrowserVersion45.0
CustomDictionary that can contain key/value pairs that can be used for Feature Gate targeting. The content of this dictionary will be stored and available after targetingcustom{current_page: "/homepage", ...}
Private AttibutesDictionary that can contain key/value pairs that can be used for Feature Gate targeting. The content of this dictionary will not be stored after used for targeting and will be removed from any log_event callsprivateAttributes{sensitive_field: "sensitive_information", ...}
Custom IDsDictionary that can contain key/value pairs used as the randomization unit ID for experiments that are set up using these IDs instead of the User IDcustomIDs{account_id: "23456555", company_id: "company_xyz"}

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!

For more information, refer to the the privateAttributes guide.

Still Stuck?

Join our Slack community and chat with our Engineers and Data Scientists