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, language: nil, platform: nil, version: nil, os: nil, device_manufacturer: nil, device_brand: nil, device_model: nil, carrier: nil, library: nil, user_properties: 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

  • 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



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/experiment/user.rb', line 87

def initialize(device_id: nil, user_id: nil, country: nil, city: nil, region: nil, dma: 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)
  @device_id = device_id
  @user_id = user_id
  @country = country
  @city = city
  @region = region
  @dma = dma
  @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
end

Instance Attribute Details

#carrierString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of carrier



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

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

#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



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

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



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

def device_manufacturer
  @device_manufacturer
end

#device_modelString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of device model



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

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

#languageString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of language



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

def language
  @language
end

#libraryString?

Predefined field, auto populated, can be manually overridden

Returns:

  • (String, nil)

    the value of library



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

def library
  @library
end

#osString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of os



45
46
47
# File 'lib/experiment/user.rb', line 45

def os
  @os
end

#platformString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of platform



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

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



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

def user_properties
  @user_properties
end

#versionString?

Predefined field, must be manually provided

Returns:

  • (String, nil)

    the value of version



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

def version
  @version
end

Instance Method Details

#as_json(_options = {}) ⇒ Hash

Return User as Hash.

Returns:

  • (Hash)

    Hash object with user values



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/experiment/user.rb', line 110

def as_json(_options = {})
  {
    device_id: @device_id,
    user_id: @user_id,
    country: @country,
    city: @city,
    region: @region,
    dma: @dma,
    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
  }
end

#to_json(*options) ⇒ String

Return user information as JSON string.

Returns:

  • (String)

    details about user as json string



133
134
135
# File 'lib/experiment/user.rb', line 133

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