Class: Kameleoon::DataManager::VisitorData

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVisitorData

Returns a new instance of VisitorData.



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

def initialize
  Logging::KameleoonLogger.debug('CALL: VisitorData.new')
  @mutex = Concurrent::ReadWriteLock.new
  @legal_consent = false
  Logging::KameleoonLogger.debug('RETURN: VisitorData.new')
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



219
220
221
# File 'lib/kameleoon/data/manager/visitor.rb', line 219

def browser
  @browser
end

Returns the value of attribute cookie.



220
221
222
# File 'lib/kameleoon/data/manager/visitor.rb', line 220

def cookie
  @cookie
end

#deviceObject (readonly)

Returns the value of attribute device.



219
220
221
# File 'lib/kameleoon/data/manager/visitor.rb', line 219

def device
  @device
end

#geolocationObject (readonly)

Returns the value of attribute geolocation.



219
220
221
# File 'lib/kameleoon/data/manager/visitor.rb', line 219

def geolocation
  @geolocation
end

#kcs_heatObject

Returns the value of attribute kcs_heat.



220
221
222
# File 'lib/kameleoon/data/manager/visitor.rb', line 220

def kcs_heat
  @kcs_heat
end

#last_activity_timeObject

Returns the value of attribute last_activity_time.



220
221
222
# File 'lib/kameleoon/data/manager/visitor.rb', line 220

def last_activity_time
  @last_activity_time
end

Returns the value of attribute legal_consent.



220
221
222
# File 'lib/kameleoon/data/manager/visitor.rb', line 220

def legal_consent
  @legal_consent
end

#mapping_identifierObject

Returns the value of attribute mapping_identifier.



220
221
222
# File 'lib/kameleoon/data/manager/visitor.rb', line 220

def mapping_identifier
  @mapping_identifier
end

#mutexObject (readonly)

Returns the value of attribute mutex.



219
220
221
# File 'lib/kameleoon/data/manager/visitor.rb', line 219

def mutex
  @mutex
end

#operating_systemObject (readonly)

Returns the value of attribute operating_system.



219
220
221
# File 'lib/kameleoon/data/manager/visitor.rb', line 219

def operating_system
  @operating_system
end

#user_agentObject

Returns the value of attribute user_agent.



220
221
222
# File 'lib/kameleoon/data/manager/visitor.rb', line 220

def user_agent
  @user_agent
end

#visitor_visitsObject

Returns the value of attribute visitor_visits.



220
221
222
# File 'lib/kameleoon/data/manager/visitor.rb', line 220

def visitor_visits
  @visitor_visits
end

Instance Method Details

#add_conversion(conversion) ⇒ Object



322
323
324
325
# File 'lib/kameleoon/data/manager/visitor.rb', line 322

def add_conversion(conversion)
  @conversions = [] if @conversions.nil?
  @conversions.push(conversion)
end

#add_custom_data(custom_data, overwrite) ⇒ Object



291
292
293
294
295
296
# File 'lib/kameleoon/data/manager/visitor.rb', line 291

def add_custom_data(custom_data, overwrite)
  @custom_data_map = {} if @custom_data_map.nil?
  if overwrite || !@custom_data_map.include?(custom_data.id)
    @custom_data_map[custom_data.id] = custom_data
  end
end

#add_page_view(page_view) ⇒ Object



298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/kameleoon/data/manager/visitor.rb', line 298

def add_page_view(page_view)
  return if page_view.url.nil? || page_view.url.empty?

  @page_view_visits = {} if @page_view_visits.nil?
  visit = @page_view_visits[page_view.url]
  if visit.nil?
    visit = DataManager::PageViewVisit.new(page_view)
  else
    visit.overwrite(page_view)
  end
  @page_view_visits[page_view.url] = visit
end

#add_page_view_visit(page_view_visit) ⇒ Object



311
312
313
314
315
316
317
318
319
320
# File 'lib/kameleoon/data/manager/visitor.rb', line 311

def add_page_view_visit(page_view_visit)
  @page_view_visits = {} if @page_view_visits.nil?
  visit = @page_view_visits[page_view_visit.page_view.url]
  if visit.nil?
    visit = page_view_visit
    @page_view_visits[page_view_visit.page_view.url] = visit
  else
    visit.merge(page_view_visit)
  end
end

#add_variation(variation, overwrite) ⇒ Object



280
281
282
283
284
285
# File 'lib/kameleoon/data/manager/visitor.rb', line 280

def add_variation(variation, overwrite)
  @variations = {} if @variations.nil?
  if overwrite || !@variations.include?(variation.experiment_id)
    @variations[variation.experiment_id] = variation
  end
end

#conversionsObject



268
269
270
# File 'lib/kameleoon/data/manager/visitor.rb', line 268

def conversions
  DataArrayStorage.new(@mutex, @conversions)
end

#count_sendable_dataObject



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/kameleoon/data/manager/visitor.rb', line 243

def count_sendable_data
  Logging::KameleoonLogger.debug('CALL: Visitor.count_sendable_data')
  count = 0
  @mutex.with_read_lock do
    count += 1 unless @device.nil?
    count += 1 unless @browser.nil?
    count += 1 unless @geolocation.nil?
    count += 1 unless @operating_system.nil?
    count += @custom_data_map.size unless @custom_data_map.nil?
    count += @page_view_visits.size unless @page_view_visits.nil?
    count += @conversions.size unless @conversions.nil?
    count += @variations.size unless @variations.nil?
  end
  Logging::KameleoonLogger.debug('RETURN: VisitorData.count_sendable_data -> (count: %s)', count)
  count
end

#custom_dataObject



260
261
262
# File 'lib/kameleoon/data/manager/visitor.rb', line 260

def custom_data
  DataMapStorage.new(@mutex, @custom_data_map)
end

#enumerate_sendable_data(&blk) ⇒ Object



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

def enumerate_sendable_data(&blk)
  blk.call(@device) unless @device.nil?
  blk.call(@browser) unless @browser.nil?
  blk.call(@operating_system) unless @operating_system.nil?
  blk.call(@geolocation) unless @geolocation.nil?
  @mutex.with_read_lock do
    @custom_data_map&.each { |_, cd| blk.call(cd) }
    @page_view_visits&.each { |_, pvv| blk.call(pvv.page_view) }
    @conversions&.each { |c| blk.call(c) }
    @variations&.each { |_, av| blk.call(av) }
  end
end

#page_view_visitsObject



264
265
266
# File 'lib/kameleoon/data/manager/visitor.rb', line 264

def page_view_visits
  DataMapStorage.new(@mutex, @page_view_visits)
end

#set_browser(browser, overwrite) ⇒ Object



287
288
289
# File 'lib/kameleoon/data/manager/visitor.rb', line 287

def set_browser(browser, overwrite)
  @browser = browser if overwrite || @browser.nil?
end

#set_device(device, overwrite) ⇒ Object



276
277
278
# File 'lib/kameleoon/data/manager/visitor.rb', line 276

def set_device(device, overwrite)
  @device = device if overwrite || @device.nil?
end

#set_geolocation(geolocation, overwrite) ⇒ Object



327
328
329
# File 'lib/kameleoon/data/manager/visitor.rb', line 327

def set_geolocation(geolocation, overwrite)
  @geolocation = geolocation if overwrite || @geolocation.nil?
end

#set_operating_system(operating_system, overwrite) ⇒ Object



331
332
333
# File 'lib/kameleoon/data/manager/visitor.rb', line 331

def set_operating_system(operating_system, overwrite)
  @operating_system = operating_system if overwrite || @operating_system.nil?
end

#variationsObject



272
273
274
# File 'lib/kameleoon/data/manager/visitor.rb', line 272

def variations
  DataMapStorage.new(@mutex, @variations)
end