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.



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

def initialize
  Logging::KameleoonLogger.debug('CALL: VisitorData.new')
  @time_started = (Time.now.to_f * 1000).to_i
  @mutex = Concurrent::ReadWriteLock.new
  @legal_consent = LegalConsent::UNKNOWN
  Logging::KameleoonLogger.debug('RETURN: VisitorData.new')
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



308
309
310
# File 'lib/kameleoon/data/manager/visitor.rb', line 308

def browser
  @browser
end

#cbscoresObject

Returns the value of attribute cbscores.



309
310
311
# File 'lib/kameleoon/data/manager/visitor.rb', line 309

def cbscores
  @cbscores
end

Returns the value of attribute cookie.



309
310
311
# File 'lib/kameleoon/data/manager/visitor.rb', line 309

def cookie
  @cookie
end

#deviceObject (readonly)

Returns the value of attribute device.



308
309
310
# File 'lib/kameleoon/data/manager/visitor.rb', line 308

def device
  @device
end

#forced_variationsObject

Returns the value of attribute forced_variations.



309
310
311
# File 'lib/kameleoon/data/manager/visitor.rb', line 309

def forced_variations
  @forced_variations
end

#geolocationObject (readonly)

Returns the value of attribute geolocation.



308
309
310
# File 'lib/kameleoon/data/manager/visitor.rb', line 308

def geolocation
  @geolocation
end

#kcs_heatObject

Returns the value of attribute kcs_heat.



309
310
311
# File 'lib/kameleoon/data/manager/visitor.rb', line 309

def kcs_heat
  @kcs_heat
end

#last_activity_timeObject

Returns the value of attribute last_activity_time.



309
310
311
# File 'lib/kameleoon/data/manager/visitor.rb', line 309

def last_activity_time
  @last_activity_time
end

Returns the value of attribute legal_consent.



309
310
311
# File 'lib/kameleoon/data/manager/visitor.rb', line 309

def legal_consent
  @legal_consent
end

#mapping_identifierObject

Returns the value of attribute mapping_identifier.



309
310
311
# File 'lib/kameleoon/data/manager/visitor.rb', line 309

def mapping_identifier
  @mapping_identifier
end

#mutexObject (readonly)

Returns the value of attribute mutex.



308
309
310
# File 'lib/kameleoon/data/manager/visitor.rb', line 308

def mutex
  @mutex
end

#operating_systemObject (readonly)

Returns the value of attribute operating_system.



308
309
310
# File 'lib/kameleoon/data/manager/visitor.rb', line 308

def operating_system
  @operating_system
end

#simulated_variationsObject

Returns the value of attribute simulated_variations.



309
310
311
# File 'lib/kameleoon/data/manager/visitor.rb', line 309

def simulated_variations
  @simulated_variations
end

#time_startedObject (readonly)

Returns the value of attribute time_started.



308
309
310
# File 'lib/kameleoon/data/manager/visitor.rb', line 308

def time_started
  @time_started
end

#user_agentObject

Returns the value of attribute user_agent.



309
310
311
# File 'lib/kameleoon/data/manager/visitor.rb', line 309

def user_agent
  @user_agent
end

#visitor_visitsObject (readonly)

Returns the value of attribute visitor_visits.



308
309
310
# File 'lib/kameleoon/data/manager/visitor.rb', line 308

def visitor_visits
  @visitor_visits
end

Instance Method Details

#add_conversion(conversion) ⇒ Object



452
453
454
455
# File 'lib/kameleoon/data/manager/visitor.rb', line 452

def add_conversion(conversion)
  @conversions ||= []
  @conversions.push(conversion)
end

#add_custom_data(custom_data, overwrite) ⇒ Object



421
422
423
424
425
426
# File 'lib/kameleoon/data/manager/visitor.rb', line 421

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

#add_forced_experiment_variation(forced_variation) ⇒ Object



478
479
480
481
# File 'lib/kameleoon/data/manager/visitor.rb', line 478

def add_forced_experiment_variation(forced_variation)
  @forced_variations ||= {}
  @forced_variations[forced_variation.rule.experiment.id] = forced_variation
end

#add_forced_feature_variation(forced_variation) ⇒ Object



473
474
475
476
# File 'lib/kameleoon/data/manager/visitor.rb', line 473

def add_forced_feature_variation(forced_variation)
  @simulated_variations ||= {}
  @simulated_variations[forced_variation.feature_key] = forced_variation
end

#add_page_view(page_view) ⇒ Object



428
429
430
431
432
433
434
435
436
437
438
439
# File 'lib/kameleoon/data/manager/visitor.rb', line 428

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

  @page_view_visits ||= {}
  visit = @page_view_visits[page_view.url]
  if visit.nil?
    visit = 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



441
442
443
444
445
446
447
448
449
450
# File 'lib/kameleoon/data/manager/visitor.rb', line 441

def add_page_view_visit(page_view_visit)
  @page_view_visits ||= {}
  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_personalization(personalization, overwrite) ⇒ Object



405
406
407
408
409
410
# File 'lib/kameleoon/data/manager/visitor.rb', line 405

def add_personalization(personalization, overwrite)
  @personalizations ||= {}
  if overwrite || !@personalizations.include?(personalization.id)
    @personalizations[personalization.id] = personalization
  end
end

#add_targeted_segment(targeted_segment) ⇒ Object



412
413
414
415
# File 'lib/kameleoon/data/manager/visitor.rb', line 412

def add_targeted_segment(targeted_segment)
  @targeted_segments ||= {}
  @targeted_segments[targeted_segment.id] = targeted_segment
end

#add_variation(variation, overwrite) ⇒ Object



398
399
400
401
402
403
# File 'lib/kameleoon/data/manager/visitor.rb', line 398

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

#conversionsObject



378
379
380
# File 'lib/kameleoon/data/manager/visitor.rb', line 378

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

#count_sendable_dataObject



351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/kameleoon/data/manager/visitor.rb', line 351

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 @operating_system.nil?
    count += 1 unless @geolocation.nil?
    count += 1 unless @visitor_visits.nil?
    count += @custom_data_map.size unless @custom_data_map.nil?
    count += @page_view_visits.size unless @page_view_visits.nil?
    count += @variations.size unless @variations.nil?
    count += @targeted_segments.size unless @targeted_segments.nil?
    count += @conversions.size unless @conversions.nil?
  end
  Logging::KameleoonLogger.debug('RETURN: VisitorData.count_sendable_data -> (count: %s)', count)
  count
end

#custom_dataObject



370
371
372
# File 'lib/kameleoon/data/manager/visitor.rb', line 370

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

#enumerate_sendable_data(&blk) ⇒ Object



336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/kameleoon/data/manager/visitor.rb', line 336

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?
  blk.call(@visitor_visits) unless @visitor_visits.nil?
  @mutex.with_read_lock do
    @custom_data_map&.each { |_, cd| blk.call(cd) }
    @page_view_visits&.each { |_, pvv| blk.call(pvv.page_view) }
    @variations&.each { |_, av| blk.call(av) }
    @targeted_segments&.each { |_, ts| blk.call(ts) }
    @conversions&.each { |c| blk.call(c) }
  end
end

#get_from_map(map, key) ⇒ Object



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

def get_from_map(map, key)
  return nil if map.nil?

  @mutex.with_read_lock do
    return map[key]
  end
end

#page_view_visitsObject



374
375
376
# File 'lib/kameleoon/data/manager/visitor.rb', line 374

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

#personalizationsObject



386
387
388
# File 'lib/kameleoon/data/manager/visitor.rb', line 386

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

#remove_from_map(map, key) ⇒ Object



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

def remove_from_map(map, key)
  return false if map.nil?

  @mutex.with_write_lock do
    return map.delete(key).nil?
  end
end

#set_browser(browser, overwrite) ⇒ Object



417
418
419
# File 'lib/kameleoon/data/manager/visitor.rb', line 417

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

#set_cbscores(cbs, overwrite) ⇒ Object



465
466
467
# File 'lib/kameleoon/data/manager/visitor.rb', line 465

def set_cbscores(cbs, overwrite)
  @cbscores = cbs if overwrite || @cbscores.nil?
end

#set_device(device, overwrite) ⇒ Object



394
395
396
# File 'lib/kameleoon/data/manager/visitor.rb', line 394

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

#set_geolocation(geolocation, overwrite) ⇒ Object



457
458
459
# File 'lib/kameleoon/data/manager/visitor.rb', line 457

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

#set_operating_system(operating_system, overwrite) ⇒ Object



461
462
463
# File 'lib/kameleoon/data/manager/visitor.rb', line 461

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

#set_visitor_visits(visitor_visits, overwrite) ⇒ Object



469
470
471
# File 'lib/kameleoon/data/manager/visitor.rb', line 469

def set_visitor_visits(visitor_visits, overwrite)
  @visitor_visits = visitor_visits.localize(@time_started) if overwrite || @visitor_visits.nil?
end

#targeted_segmentsObject



390
391
392
# File 'lib/kameleoon/data/manager/visitor.rb', line 390

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

#variationsObject



382
383
384
# File 'lib/kameleoon/data/manager/visitor.rb', line 382

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