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.
-
#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.
24 25 26 27 28 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 24 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 |
#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.
22 23 24 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 22 def @legal_consent end |
#mapping_identifier ⇒ Object
Returns the value of attribute mapping_identifier.
22 23 24 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 22 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
78 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 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 78 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::VisitorVisits set_visitor_visits(data) else log_func&.call("Data has unsupported type '#{data.class}'") end end end end |
#assign_variation(variation) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 113 def assign_variation(variation) @mutex.with_write_lock do @variations = {} if @variations.nil? @variations[variation.experiment_id] = variation end end |
#conversions ⇒ Object
70 71 72 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 70 def conversions DataArrayStorage.new(@mutex, @conversions) end |
#count_sendable_data ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 47 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
62 63 64 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 62 def custom_data DataMapStorage.new(@mutex, @custom_data_map) end |
#enumerate_sendable_data(&blk) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 34 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
66 67 68 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 66 def page_view_visits DataMapStorage.new(@mutex, @page_view_visits) end |
#update_last_activity_time ⇒ Object
30 31 32 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 30 def update_last_activity_time @last_activity_time = Time.new.to_i end |
#variations ⇒ Object
74 75 76 |
# File 'lib/kameleoon/data/manager/visitor.rb', line 74 def variations DataMapStorage.new(@mutex, @variations) end |