Class: StatsigUser
Overview
The user object to be evaluated against your Statsig configurations (gates/experiments/dynamic configs).
Instance Attribute Summary collapse
-
#app_version ⇒ Object
The current app version the user is interacting with.
-
#country ⇒ Object
The country code associated with this user (e.g New Zealand => NZ).
-
#custom_ids ⇒ Object
Any Custom IDs to associated with the user.
-
#email ⇒ Object
An identifier for this user.
-
#ip ⇒ Object
An IP address associated with this user.
-
#locale ⇒ Object
An locale for this user.
-
#private_attributes ⇒ Object
Any value you wish to use in evaluation, but do not want logged with events, can be stored in this field.
-
#statsig_environment ⇒ Object
A Hash you can use to set environment variables that apply to this user.
-
#user_agent ⇒ Object
A user agent string associated with this user.
-
#user_id ⇒ Object
An identifier for this user.
Instance Method Summary collapse
- #custom ⇒ Object
-
#custom=(value) ⇒ Object
Any custom fields for this user.
-
#initialize(user_hash) ⇒ StatsigUser
constructor
A new instance of StatsigUser.
- #serialize(for_logging) ⇒ Object
- #value_lookup ⇒ Object
Constructor Details
#initialize(user_hash) ⇒ StatsigUser
Returns a new instance of StatsigUser.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/statsig_user.rb', line 64 def initialize(user_hash) @user_id = from_hash(user_hash, [:user_id, :userID], String) @email = from_hash(user_hash, [:email], String) @ip = from_hash(user_hash, [:ip], String) @user_agent = from_hash(user_hash, [:user_agent, :userAgent], String) @country = from_hash(user_hash, [:country], String) @locale = from_hash(user_hash, [:locale], String) @app_version = from_hash(user_hash, [:app_version, :appVersion], String) @custom = from_hash(user_hash, [:custom], Hash) @private_attributes = from_hash(user_hash, [:private_attributes, :privateAttributes], Hash) @custom_ids = from_hash(user_hash, [:custom_ids, :customIDs], Hash) @statsig_environment = from_hash(user_hash, [:statsig_environment, :statsigEnvironment], Hash) end |
Instance Attribute Details
#app_version ⇒ Object
The current app version the user is interacting with. Evaluated against the App Version criteria. (docs.statsig.com/feature-gates/conditions#app-version)
36 37 38 |
# File 'lib/statsig_user.rb', line 36 def app_version @app_version end |
#country ⇒ Object
The country code associated with this user (e.g New Zealand => NZ). Evaluated against the Country criteria. (docs.statsig.com/feature-gates/conditions#country)
28 29 30 |
# File 'lib/statsig_user.rb', line 28 def country @country end |
#custom_ids ⇒ Object
Any Custom IDs to associated with the user. (See docs.statsig.com/guides/experiment-on-custom-id-types)
44 45 46 |
# File 'lib/statsig_user.rb', line 44 def custom_ids @custom_ids end |
#email ⇒ Object
An identifier for this user. Evaluated against the Email criteria. (docs.statsig.com/feature-gates/conditions#email)
16 17 18 |
# File 'lib/statsig_user.rb', line 16 def email @email end |
#ip ⇒ Object
An IP address associated with this user. Evaluated against the IP Address criteria. (docs.statsig.com/feature-gates/conditions#ip)
20 21 22 |
# File 'lib/statsig_user.rb', line 20 def ip @ip end |
#locale ⇒ Object
An locale for this user.
32 33 34 |
# File 'lib/statsig_user.rb', line 32 def locale @locale end |
#private_attributes ⇒ Object
Any value you wish to use in evaluation, but do not want logged with events, can be stored in this field.
48 49 50 |
# File 'lib/statsig_user.rb', line 48 def private_attributes @private_attributes end |
#statsig_environment ⇒ Object
A Hash you can use to set environment variables that apply to this user. e.g. { “tier” => “development” }
40 41 42 |
# File 'lib/statsig_user.rb', line 40 def statsig_environment @statsig_environment end |
#user_agent ⇒ Object
A user agent string associated with this user. Evaluated against Browser Version and Name (docs.statsig.com/feature-gates/conditions#browser-version)
24 25 26 |
# File 'lib/statsig_user.rb', line 24 def user_agent @user_agent end |
#user_id ⇒ Object
An identifier for this user. Evaluated against the User ID criteria. (docs.statsig.com/feature-gates/conditions#userid)
12 13 14 |
# File 'lib/statsig_user.rb', line 12 def user_id @user_id end |
Instance Method Details
#custom ⇒ Object
52 53 54 |
# File 'lib/statsig_user.rb', line 52 def custom @custom end |
#custom=(value) ⇒ Object
Any custom fields for this user. Evaluated against the Custom criteria. (docs.statsig.com/feature-gates/conditions#custom)
58 59 60 |
# File 'lib/statsig_user.rb', line 58 def custom=(value) @custom = value.is_a?(Hash) ? value : Hash.new end |
#serialize(for_logging) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/statsig_user.rb', line 78 def serialize(for_logging) hash = { 'userID' => @user_id, 'email' => @email, 'ip' => @ip, 'userAgent' => @user_agent, 'country' => @country, 'locale' => @locale, 'appVersion' => @app_version, 'custom' => @custom, 'statsigEnvironment' => @statsig_environment, 'privateAttributes' => @private_attributes, 'customIDs' => @custom_ids, } if for_logging hash.delete('privateAttributes') end hash.compact end |
#value_lookup ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/statsig_user.rb', line 98 def value_lookup { 'userID' => @user_id, 'userid' => @user_id, 'user_id' => @user_id, 'email' => @email, 'ip' => @ip, 'userAgent' => @user_agent, 'useragent' => @user_agent, 'user_agent' => @user_agent, 'country' => @country, 'locale' => @locale, 'appVersion' => @app_version, 'appversion' => @app_version, 'app_version' => @app_version, 'custom' => @custom, 'privateAttributes' => @private_attributes, } end |