Class: Kameleoon::DataManager::Visitor
- Inherits:
-
Object
- Object
- Kameleoon::DataManager::Visitor
- 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
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
-
#cookie ⇒ Object
readonly
Returns the value of attribute cookie.
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#geolocation ⇒ Object
readonly
Returns the value of attribute geolocation.
-
#kcs_heat ⇒ Object
readonly
Returns the value of attribute kcs_heat.
-
#last_activity_time ⇒ Object
readonly
Returns the value of attribute last_activity_time.
-
#legal_consent ⇒ Object
Returns the value of attribute legal_consent.
-
#mapping_identifier ⇒ Object
Returns the value of attribute mapping_identifier.
-
#operating_system ⇒ Object
readonly
Returns the value of attribute operating_system.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
-
#visitor_visits ⇒ Object
readonly
Returns the value of attribute visitor_visits.
Instance Method Summary collapse
- #add_data(log_func, *args, overwrite: true) ⇒ Object
- #assign_variation(variation) ⇒ Object
- #conversions ⇒ Object
- #count_sendable_data ⇒ Object
- #custom_data ⇒ Object
- #enumerate_sendable_data(&blk) ⇒ Object
-
#initialize ⇒ Visitor
constructor
A new instance of Visitor.
- #page_view_visits ⇒ Object
- #update_last_activity_time ⇒ Object
- #variations ⇒ Object
Constructor Details
#initialize ⇒ Visitor
Returns a new instance of Visitor.
25 26 27 28 29 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 25 def initialize @mutex = Concurrent::ReadWriteLock.new @legal_consent = false update_last_activity_time end |
Instance Attribute Details
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
21 22 23 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 21 def browser @browser end |
#cookie ⇒ Object (readonly)
Returns the value of attribute cookie.
21 22 23 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 21 def @cookie end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
21 22 23 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 21 def device @device end |
#geolocation ⇒ Object (readonly)
Returns the value of attribute geolocation.
21 22 23 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 21 def geolocation @geolocation end |
#kcs_heat ⇒ Object (readonly)
Returns the value of attribute kcs_heat.
21 22 23 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 21 def kcs_heat @kcs_heat end |
#last_activity_time ⇒ Object (readonly)
Returns the value of attribute last_activity_time.
21 22 23 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 21 def last_activity_time @last_activity_time end |
#legal_consent ⇒ Object
Returns the value of attribute legal_consent.
23 24 25 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 23 def @legal_consent end |
#mapping_identifier ⇒ Object
Returns the value of attribute mapping_identifier.
23 24 25 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 23 def mapping_identifier @mapping_identifier end |
#operating_system ⇒ Object (readonly)
Returns the value of attribute operating_system.
21 22 23 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 21 def @operating_system end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
21 22 23 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 21 def user_agent @user_agent end |
#visitor_visits ⇒ Object (readonly)
Returns the value of attribute visitor_visits.
21 22 23 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 21 def visitor_visits @visitor_visits end |
Instance Method Details
#add_data(log_func, *args, overwrite: true) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 79 def add_data(log_func, *args, overwrite: true) @mutex.with_write_lock do args.each do |data| case data when Kameleoon::UserAgent set_user_agent(data) when Kameleoon::DataManager::AssignedVariation add_variation(data, overwrite) when Kameleoon::Device set_device(data, overwrite) when Kameleoon::Browser set_browser(data, overwrite) when Kameleoon::CustomData add_custom_data(data, overwrite) when Kameleoon::PageView add_page_view(data) when Kameleoon::DataManager::PageViewVisit add_page_view_visit(data) when Kameleoon::Conversion add_conversion(data) when Kameleoon::Cookie (data) when Kameleoon::OperatingSystem (data, overwrite) when Kameleoon::Geolocation set_geolocation(data, overwrite) when Kameleoon::KcsHeat set_kcs_heat(data) when Kameleoon::VisitorVisits set_visitor_visits(data) else log_func&.call("Data has unsupported type '#{data.class}'") end end end end |
#assign_variation(variation) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 116 def assign_variation(variation) @mutex.with_write_lock do @variations = {} if @variations.nil? @variations[variation.experiment_id] = variation end end |
#conversions ⇒ Object
71 72 73 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 71 def conversions DataArrayStorage.new(@mutex, @conversions) end |
#count_sendable_data ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 48 def 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 count end |
#custom_data ⇒ Object
63 64 65 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 63 def custom_data DataMapStorage.new(@mutex, @custom_data_map) end |
#enumerate_sendable_data(&blk) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 35 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_visits ⇒ Object
67 68 69 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 67 def page_view_visits DataMapStorage.new(@mutex, @page_view_visits) end |
#update_last_activity_time ⇒ Object
31 32 33 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 31 def update_last_activity_time @last_activity_time = Time.new.to_i end |
#variations ⇒ Object
75 76 77 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 75 def variations DataMapStorage.new(@mutex, @variations) end |