Class: Kameleoon::DataManager::Visitor

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/data/manager/visitor.rb

Overview

Visitor is a container of all data assigned to a visitor. It is thread-safe

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source = nil) ⇒ Visitor

Returns a new instance of Visitor.



37
38
39
40
41
42
43
44
45
46
# File 'lib/kameleoon/data/manager/visitor.rb', line 37

def initialize(source = nil)
  if source.nil?
    @data = VisitorData.new
    @is_unique_identifier = false
  else
    @data = source.data
    @is_unique_identifier = source.is_unique_identifier
  end
  update_last_activity_time
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



31
32
33
# File 'lib/kameleoon/data/manager/visitor.rb', line 31

def data
  @data
end

#is_unique_identifierObject (readonly)

Returns the value of attribute is_unique_identifier.



31
32
33
# File 'lib/kameleoon/data/manager/visitor.rb', line 31

def is_unique_identifier
  @is_unique_identifier
end

Instance Method Details

#add_data(*args, overwrite: true) ⇒ Object



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/kameleoon/data/manager/visitor.rb', line 243

def add_data(*args, overwrite: true)
  Logging::KameleoonLogger.debug('CALL: Visitor.add_data(args: %s, overwrite: %s)', args, overwrite)
  @data.mutex.with_write_lock do
    args.each do |data|
      next if data.nil?

      case data
      when UserAgent
        @data.user_agent = data.value
      when AssignedVariation
        @data.add_variation(data, overwrite)
      when Personalization
        @data.add_personalization(data, overwrite)
      when TargetedSegment
        @data.add_targeted_segment(data)
      when ForcedFeatureVariation
        @data.add_forced_feature_variation(data)
      when ForcedExperimentVariation
        @data.add_forced_experiment_variation(data)
      when Device
        @data.set_device(data, overwrite)
      when Browser
        @data.set_browser(data, overwrite)
      when CustomData
        @data.add_custom_data(data, overwrite)
      when PageView
        @data.add_page_view(data)
      when PageViewVisit
        @data.add_page_view_visit(data)
      when Conversion
        @data.add_conversion(data)
      when Cookie
        @data.cookie = data
      when OperatingSystem
        @data.set_operating_system(data, overwrite)
      when Geolocation
        @data.set_geolocation(data, overwrite)
      when KcsHeat
        @data.kcs_heat = data
      when CBScores
        @data.set_cbscores(data, overwrite)
      when VisitorVisits
        @data.set_visitor_visits(data, overwrite)
      when UniqueIdentifier
        @is_unique_identifier = data.value
      else
        Logging::KameleoonLogger.warning("Data has unsupported type '%s'", data.class)
      end
    end
  end
  Logging::KameleoonLogger.debug('RETURN: Visitor.add_data(args: %s, overwrite: %s)', args, overwrite)
end

#assign_variation(variation) ⇒ Object



296
297
298
299
300
# File 'lib/kameleoon/data/manager/visitor.rb', line 296

def assign_variation(variation)
  @data.mutex.with_write_lock do
    @data.add_variation(variation, true)
  end
end

#browserObject



85
86
87
88
89
# File 'lib/kameleoon/data/manager/visitor.rb', line 85

def browser
  browser = @data.browser
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.browser -> (browser: %s)', browser)
  browser
end

#cbscoresObject



118
119
120
121
122
# File 'lib/kameleoon/data/manager/visitor.rb', line 118

def cbscores
  cbs = @data.cbscores
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.cbscores -> (cbs: %s)', cbs)
  cbs
end

#cloneObject



302
303
304
# File 'lib/kameleoon/data/manager/visitor.rb', line 302

def clone
  Visitor.new(self)
end

#conversionsObject



171
172
173
174
175
# File 'lib/kameleoon/data/manager/visitor.rb', line 171

def conversions
  conversions = @data.conversions
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.conversions -> (conversions: %s)', conversions)
  conversions
end


106
107
108
109
110
# File 'lib/kameleoon/data/manager/visitor.rb', line 106

def cookie
  cookie = @data.cookie
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.cookie -> (cookie: %s)', cookie)
  cookie
end

#count_sendable_dataObject



64
65
66
67
68
69
70
71
# File 'lib/kameleoon/data/manager/visitor.rb', line 64

def count_sendable_data
  count_sendable_data = @data.count_sendable_data
  Logging::KameleoonLogger.debug(
    'CALL/RETURN: Visitor.count_sendable_data -> (count_sendable_data: %s)',
    count_sendable_data
  )
  count_sendable_data
end

#custom_dataObject



158
159
160
161
162
# File 'lib/kameleoon/data/manager/visitor.rb', line 158

def custom_data
  custom_data = @data.custom_data
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.custom_data -> (custom_data: %s)', custom_data)
  custom_data
end

#deviceObject



79
80
81
82
83
# File 'lib/kameleoon/data/manager/visitor.rb', line 79

def device
  device = @data.device
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.device -> (device: %s)', device)
  device
end

#enumerate_sendable_data(&blk) ⇒ Object



60
61
62
# File 'lib/kameleoon/data/manager/visitor.rb', line 60

def enumerate_sendable_data(&blk)
  @data.enumerate_sendable_data(&blk)
end

#geolocationObject



91
92
93
94
95
# File 'lib/kameleoon/data/manager/visitor.rb', line 91

def geolocation
  geolocation = @data.geolocation
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.geolocation -> (geolocation: %s)', geolocation)
  geolocation
end

#get_forced_experiment_variation(experiment_id) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
# File 'lib/kameleoon/data/manager/visitor.rb', line 209

def get_forced_experiment_variation(experiment_id)
  Logging::KameleoonLogger.debug(
    'CALL: Visitor.get_forced_experiment_variation(experiment_id: %d)', experiment_id
  )
  variation = @data.get_from_map(@data.forced_variations, experiment_id)
  Logging::KameleoonLogger.debug(
    'RETURN: Visitor.get_forced_experiment_variation(experiment_id: %d) -> (variation: %s)',
    experiment_id, variation
  )
  variation
end

#get_forced_feature_variation(feature_key) ⇒ Object



199
200
201
202
203
204
205
206
207
# File 'lib/kameleoon/data/manager/visitor.rb', line 199

def get_forced_feature_variation(feature_key)
  Logging::KameleoonLogger.debug("CALL: Visitor.get_forced_feature_variation(feature_key: '%s')", feature_key)
  variation = @data.get_from_map(@data.simulated_variations, feature_key)
  Logging::KameleoonLogger.debug(
    "RETURN: Visitor.get_forced_feature_variation(feature_key: '%s') -> (variation: %s)",
    feature_key, variation
  )
  variation
end

#kcs_heatObject



112
113
114
115
116
# File 'lib/kameleoon/data/manager/visitor.rb', line 112

def kcs_heat
  kcs_heat = @data.kcs_heat
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.kcs_heat -> (kcs_heat: %s)', kcs_heat)
  kcs_heat
end

#last_activity_timeObject



52
53
54
# File 'lib/kameleoon/data/manager/visitor.rb', line 52

def last_activity_time
  @data.last_activity_time
end


130
131
132
133
134
# File 'lib/kameleoon/data/manager/visitor.rb', line 130

def legal_consent
  legal_consent = @data.legal_consent
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.legal_consent -> (legal_consent: %s)', legal_consent)
  legal_consent
end


136
137
138
# File 'lib/kameleoon/data/manager/visitor.rb', line 136

def legal_consent=(value)
  @data.legal_consent = value
end

#mapping_identifierObject



140
141
142
143
144
145
# File 'lib/kameleoon/data/manager/visitor.rb', line 140

def mapping_identifier
  mapping_identifier = @data.mapping_identifier
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.mapping_identifier -> (mapping_identifier: %s)',
                                 mapping_identifier)
  mapping_identifier
end

#mapping_identifier=(value) ⇒ Object



147
148
149
150
151
152
153
154
155
156
# File 'lib/kameleoon/data/manager/visitor.rb', line 147

def mapping_identifier=(value)
  return unless @data.mapping_identifier.nil?

  @data.mutex.with_write_lock do
    if @data.mapping_identifier.nil?
      @data.mapping_identifier = value
      Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.mapping_identifier = %s', value)
    end
  end
end

#operating_systemObject



97
98
99
100
101
102
103
104
# File 'lib/kameleoon/data/manager/visitor.rb', line 97

def operating_system
  operating_system = @data.operating_system
  Logging::KameleoonLogger.debug(
    'CALL/RETURN: Visitor.operating_system -> (operating_system: %s)',
    operating_system
  )
  operating_system
end

#page_view_visitsObject



164
165
166
167
168
169
# File 'lib/kameleoon/data/manager/visitor.rb', line 164

def page_view_visits
  page_view_visits = @data.page_view_visits
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.page_view_visits -> (page_view_visits: %s)',
                                 page_view_visits)
  page_view_visits
end

#personalizationsObject



183
184
185
186
187
188
189
# File 'lib/kameleoon/data/manager/visitor.rb', line 183

def personalizations
  personalizations = @data.personalizations
  Logging::KameleoonLogger.debug(
    'CALL/RETURN: Visitor.personalizations -> (personalizations: %s)', personalizations
  )
  personalizations
end

#reset_forced_experiment_variation(experiment_id) ⇒ Object



221
222
223
224
225
226
227
228
229
# File 'lib/kameleoon/data/manager/visitor.rb', line 221

def reset_forced_experiment_variation(experiment_id)
  Logging::KameleoonLogger.debug(
    'CALL: Visitor.reset_forced_experiment_variation(experiment_id: %d)', experiment_id
  )
  @data.remove_from_map(@data.forced_variations, experiment_id)
  Logging::KameleoonLogger.debug(
    'RETURN: Visitor.reset_forced_experiment_variation(experiment_id: %d)', experiment_id
  )
end

#targeted_segmentsObject



191
192
193
194
195
196
197
# File 'lib/kameleoon/data/manager/visitor.rb', line 191

def targeted_segments
  targeted_segments = @data.targeted_segments
  Logging::KameleoonLogger.debug(
    'CALL/RETURN: Visitor.targeted_segments -> (targeted_segments: %s)', targeted_segments
  )
  targeted_segments
end

#time_startedObject



48
49
50
# File 'lib/kameleoon/data/manager/visitor.rb', line 48

def time_started
  @data.time_started
end

#to_sObject



33
34
35
# File 'lib/kameleoon/data/manager/visitor.rb', line 33

def to_s
  'Visitor{}'
end

#update_last_activity_timeObject



56
57
58
# File 'lib/kameleoon/data/manager/visitor.rb', line 56

def update_last_activity_time
  @data.last_activity_time = Time.new.to_i
end

#update_simulated_variations(variations) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
# File 'lib/kameleoon/data/manager/visitor.rb', line 231

def update_simulated_variations(variations)
  return if (@data.simulated_variations.nil? || @data.simulated_variations.empty?) && variations.empty?

  Logging::KameleoonLogger.debug('CALL: Visitor.update_simulated_variations(variations: %s)', variations)
  new_simulated_variations = {}
  variations.each { |sv| new_simulated_variations[sv.feature_key] = sv }
  @data.mutex.with_write_lock do
    @data.simulated_variations = new_simulated_variations
  end
  Logging::KameleoonLogger.debug('RETURN: Visitor.update_simulated_variations(variations: %s)', variations)
end

#user_agentObject



73
74
75
76
77
# File 'lib/kameleoon/data/manager/visitor.rb', line 73

def user_agent
  user_agent = @data.user_agent
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.user_agent -> (user_agent: %s)', user_agent)
  user_agent
end

#variationsObject



177
178
179
180
181
# File 'lib/kameleoon/data/manager/visitor.rb', line 177

def variations
  variations = @data.variations
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.variations -> (variations: %s)', variations)
  variations
end

#visitor_visitsObject



124
125
126
127
128
# File 'lib/kameleoon/data/manager/visitor.rb', line 124

def visitor_visits
  visitor_visits = @data.visitor_visits
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.visitor_visits -> (visitor_visits: %s)', visitor_visits)
  visitor_visits
end