Class: AmplitudeExperiment::User
- Inherits:
-
Object
- Object
- AmplitudeExperiment::User
- Defined in:
- lib/experiment/user.rb
Overview
Defines a user context for evaluation. ‘device_id` and `user_id` are used for identity resolution. All other predefined fields and user properties are used for rule based user targeting.
Instance Attribute Summary collapse
-
#carrier ⇒ String?
Predefined field, must be manually provided.
-
#city ⇒ String?
Predefined field, must be manually provided.
-
#cohort_ids ⇒ Hash?
Cohort IDs for the user.
-
#country ⇒ String?
Predefined field, must be manually provided.
-
#device_brand ⇒ String?
Predefined field, must be manually provided.
-
#device_id ⇒ String?
Device ID for associating with an identity in Amplitude.
-
#device_manufacturer ⇒ String?
Predefined field, must be manually provided.
-
#device_model ⇒ String?
Predefined field, must be manually provided.
-
#dma ⇒ String?
Predefined field, must be manually provided.
-
#group_cohort_ids ⇒ Hash?
Cohort IDs for the user’s groups.
-
#group_properties ⇒ Hash?
Predefined field, must be manually provided.
-
#groups ⇒ Hash?
Predefined field, must be manually provided.
-
#ip_address ⇒ String?
Predefined field, must be manually provided.
-
#language ⇒ String?
Predefined field, must be manually provided.
-
#library ⇒ String?
Predefined field, auto populated, can be manually overridden.
-
#os ⇒ String?
Predefined field, must be manually provided.
-
#platform ⇒ String?
Predefined field, must be manually provided.
-
#region ⇒ String?
Predefined field, must be manually provided.
-
#user_id ⇒ String?
User ID for associating with an identity in Amplitude.
-
#user_properties ⇒ Hash?
Custom user properties.
-
#version ⇒ String?
Predefined field, must be manually provided.
Instance Method Summary collapse
- #add_group_cohort_ids(group_type, group_name, cohort_ids) ⇒ Object
-
#as_json(_options = {}) ⇒ Hash
Return User as Hash.
-
#initialize(device_id: nil, user_id: nil, country: nil, city: nil, region: nil, dma: nil, ip_address: nil, language: nil, platform: nil, version: nil, os: nil, device_manufacturer: nil, device_brand: nil, device_model: nil, carrier: nil, library: nil, user_properties: nil, groups: nil, group_properties: nil, cohort_ids: nil, group_cohort_ids: nil) ⇒ User
constructor
A new instance of User.
-
#to_json(*options) ⇒ String
Return user information as JSON string.
Constructor Details
#initialize(device_id: nil, user_id: nil, country: nil, city: nil, region: nil, dma: nil, ip_address: nil, language: nil, platform: nil, version: nil, os: nil, device_manufacturer: nil, device_brand: nil, device_model: nil, carrier: nil, library: nil, user_properties: nil, groups: nil, group_properties: nil, cohort_ids: nil, group_cohort_ids: nil) ⇒ User
Returns a new instance of User.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/experiment/user.rb', line 110 def initialize(device_id: nil, user_id: nil, country: nil, city: nil, region: nil, dma: nil, ip_address: nil, language: nil, platform: nil, version: nil, os: nil, device_manufacturer: nil, device_brand: nil, device_model: nil, carrier: nil, library: nil, user_properties: nil, groups: nil, group_properties: nil, cohort_ids: nil, group_cohort_ids: nil) @device_id = device_id @user_id = user_id @country = country @city = city @region = region @dma = dma @ip_address = ip_address @language = language @platform = platform @version = version @os = os @device_manufacturer = device_manufacturer @device_brand = device_brand @device_model = device_model @carrier = carrier @library = library @user_properties = user_properties @groups = groups @group_properties = group_properties @cohort_ids = cohort_ids @group_cohort_ids = group_cohort_ids end |
Instance Attribute Details
#carrier ⇒ String?
Predefined field, must be manually provided
65 66 67 |
# File 'lib/experiment/user.rb', line 65 def carrier @carrier end |
#city ⇒ String?
Predefined field, must be manually provided
21 22 23 |
# File 'lib/experiment/user.rb', line 21 def city @city end |
#cohort_ids ⇒ Hash?
Cohort IDs for the user
85 86 87 |
# File 'lib/experiment/user.rb', line 85 def cohort_ids @cohort_ids end |
#country ⇒ String?
Predefined field, must be manually provided
17 18 19 |
# File 'lib/experiment/user.rb', line 17 def country @country end |
#device_brand ⇒ String?
Predefined field, must be manually provided
57 58 59 |
# File 'lib/experiment/user.rb', line 57 def device_brand @device_brand end |
#device_id ⇒ String?
Device ID for associating with an identity in Amplitude
9 10 11 |
# File 'lib/experiment/user.rb', line 9 def device_id @device_id end |
#device_manufacturer ⇒ String?
Predefined field, must be manually provided
53 54 55 |
# File 'lib/experiment/user.rb', line 53 def device_manufacturer @device_manufacturer end |
#device_model ⇒ String?
Predefined field, must be manually provided
61 62 63 |
# File 'lib/experiment/user.rb', line 61 def device_model @device_model end |
#dma ⇒ String?
Predefined field, must be manually provided
29 30 31 |
# File 'lib/experiment/user.rb', line 29 def dma @dma end |
#group_cohort_ids ⇒ Hash?
Cohort IDs for the user’s groups
89 90 91 |
# File 'lib/experiment/user.rb', line 89 def group_cohort_ids @group_cohort_ids end |
#group_properties ⇒ Hash?
Predefined field, must be manually provided
81 82 83 |
# File 'lib/experiment/user.rb', line 81 def group_properties @group_properties end |
#groups ⇒ Hash?
Predefined field, must be manually provided
77 78 79 |
# File 'lib/experiment/user.rb', line 77 def groups @groups end |
#ip_address ⇒ String?
Predefined field, must be manually provided
33 34 35 |
# File 'lib/experiment/user.rb', line 33 def ip_address @ip_address end |
#language ⇒ String?
Predefined field, must be manually provided
37 38 39 |
# File 'lib/experiment/user.rb', line 37 def language @language end |
#library ⇒ String?
Predefined field, auto populated, can be manually overridden
69 70 71 |
# File 'lib/experiment/user.rb', line 69 def library @library end |
#os ⇒ String?
Predefined field, must be manually provided
49 50 51 |
# File 'lib/experiment/user.rb', line 49 def os @os end |
#platform ⇒ String?
Predefined field, must be manually provided
41 42 43 |
# File 'lib/experiment/user.rb', line 41 def platform @platform end |
#region ⇒ String?
Predefined field, must be manually provided
25 26 27 |
# File 'lib/experiment/user.rb', line 25 def region @region end |
#user_id ⇒ String?
User ID for associating with an identity in Amplitude
13 14 15 |
# File 'lib/experiment/user.rb', line 13 def user_id @user_id end |
#user_properties ⇒ Hash?
Custom user properties
73 74 75 |
# File 'lib/experiment/user.rb', line 73 def user_properties @user_properties end |
#version ⇒ String?
Predefined field, must be manually provided
45 46 47 |
# File 'lib/experiment/user.rb', line 45 def version @version end |
Instance Method Details
#add_group_cohort_ids(group_type, group_name, cohort_ids) ⇒ Object
171 172 173 174 175 176 |
# File 'lib/experiment/user.rb', line 171 def add_group_cohort_ids(group_type, group_name, cohort_ids) @group_cohort_ids ||= {} group_names = @group_cohort_ids[group_type] ||= {} group_names[group_name] = cohort_ids end |
#as_json(_options = {}) ⇒ Hash
Return User as Hash.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/experiment/user.rb', line 139 def as_json( = {}) { 'device_id' => @device_id, 'user_id' => @user_id, 'country' => @country, 'city' => @city, 'region' => @region, 'dma' => @dma, 'ip_address' => @ip_address, 'language' => @language, 'platform' => @platform, 'version' => @version, 'os' => @os, 'device_manufacturer' => @device_manufacturer, 'device_brand' => @device_brand, 'device_model' => @device_model, 'carrier' => @carrier, 'library' => @library, 'user_properties' => @user_properties, 'groups' => @groups, 'group_properties' => @group_properties, 'cohort_ids' => @cohort_ids, 'group_cohort_ids' => @group_cohort_ids }.compact end |
#to_json(*options) ⇒ String
Return user information as JSON string.
167 168 169 |
# File 'lib/experiment/user.rb', line 167 def to_json(*) as_json(*).to_json(*) end |