Class: AmplitudeExperiment::User

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:

  • device_id (String, nil) (defaults to: nil)

    Device ID for associating with an identity in Amplitude

  • user_id (String, nil) (defaults to: nil)

    User ID for associating with an identity in Amplitude

  • country (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • city (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • region (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • dma (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • ip_address (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • language (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • platform (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • version (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • os (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • device_manufacturer (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • device_brand (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • device_model (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • carrier (String, nil) (defaults to: nil)

    Predefined field, must be manually provided

  • library (String, nil) (defaults to: nil)

    Predefined field, auto populated, can be manually overridden

  • user_properties (Hash, nil) (defaults to: nil)

    Custom user properties

  • groups (Hash, nil) (defaults to: nil)

    List of groups the user belongs to

  • group_properties (Hash, nil) (defaults to: nil)

    Custom properties for groups



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

#carrierString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of carrier



65
66
67
# File 'lib/experiment/user.rb', line 65

def carrier
  @carrier
end

#cityString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of city



21
22
23
# File 'lib/experiment/user.rb', line 21

def city
  @city
end

#cohort_idsHash?

Cohort IDs for the user

Returns:

  • (Hash, nil)

    the value of cohort_ids



85
86
87
# File 'lib/experiment/user.rb', line 85

def cohort_ids
  @cohort_ids
end

#countryString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of country



17
18
19
# File 'lib/experiment/user.rb', line 17

def country
  @country
end

#device_brandString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of device brand



57
58
59
# File 'lib/experiment/user.rb', line 57

def device_brand
  @device_brand
end

#device_idString?

Device ID for associating with an identity in Amplitude

Returns:

  • (String, nil)

    the value of device id



9
10
11
# File 'lib/experiment/user.rb', line 9

def device_id
  @device_id
end

#device_manufacturerString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of device manufacturer



53
54
55
# File 'lib/experiment/user.rb', line 53

def device_manufacturer
  @device_manufacturer
end

#device_modelString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of device model



61
62
63
# File 'lib/experiment/user.rb', line 61

def device_model
  @device_model
end

#dmaString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of dma



29
30
31
# File 'lib/experiment/user.rb', line 29

def dma
  @dma
end

#group_cohort_idsHash?

Cohort IDs for the user’s groups

Returns:

  • (Hash, nil)

    the value of group_cohort_ids



89
90
91
# File 'lib/experiment/user.rb', line 89

def group_cohort_ids
  @group_cohort_ids
end

#group_propertiesHash?

Predefined field, must be manually provided

Returns:

  • (Hash, nil)

    the value of group properties



81
82
83
# File 'lib/experiment/user.rb', line 81

def group_properties
  @group_properties
end

#groupsHash?

Predefined field, must be manually provided

Returns:

  • (Hash, nil)

    the value of groups



77
78
79
# File 'lib/experiment/user.rb', line 77

def groups
  @groups
end

#ip_addressString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of ip address



33
34
35
# File 'lib/experiment/user.rb', line 33

def ip_address
  @ip_address
end

#languageString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of language



37
38
39
# File 'lib/experiment/user.rb', line 37

def language
  @language
end

#libraryString?

Predefined field, auto populated, can be manually overridden

Returns:

  • (String, nil)

    the value of library



69
70
71
# File 'lib/experiment/user.rb', line 69

def library
  @library
end

#osString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of os



49
50
51
# File 'lib/experiment/user.rb', line 49

def os
  @os
end

#platformString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of platform



41
42
43
# File 'lib/experiment/user.rb', line 41

def platform
  @platform
end

#regionString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of region



25
26
27
# File 'lib/experiment/user.rb', line 25

def region
  @region
end

#user_idString?

User ID for associating with an identity in Amplitude

Returns:

  • (String, nil)

    the value of user id



13
14
15
# File 'lib/experiment/user.rb', line 13

def user_id
  @user_id
end

#user_propertiesHash?

Custom user properties

Returns:

  • (Hash, nil)

    the value of user properties



73
74
75
# File 'lib/experiment/user.rb', line 73

def user_properties
  @user_properties
end

#versionString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of version



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.

Returns:

  • (Hash)

    Hash object with user values



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(_options = {})
  {
    '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.

Returns:

  • (String)

    details about user as json string



167
168
169
# File 'lib/experiment/user.rb', line 167

def to_json(*options)
  as_json(*options).to_json(*options)
end