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.



30
31
32
33
34
35
36
37
38
39
# File 'lib/kameleoon/data/manager/visitor.rb', line 30

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.



24
25
26
# File 'lib/kameleoon/data/manager/visitor.rb', line 24

def data
  @data
end

#is_unique_identifierObject (readonly)

Returns the value of attribute is_unique_identifier.



24
25
26
# File 'lib/kameleoon/data/manager/visitor.rb', line 24

def is_unique_identifier
  @is_unique_identifier
end

Instance Method Details

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



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/kameleoon/data/manager/visitor.rb', line 166

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|
      case data
      when Kameleoon::UserAgent
        @data.user_agent = data.value
      when Kameleoon::DataManager::AssignedVariation
        @data.add_variation(data, overwrite)
      when Kameleoon::Device
        @data.set_device(data, overwrite)
      when Kameleoon::Browser
        @data.set_browser(data, overwrite)
      when Kameleoon::CustomData
        @data.add_custom_data(data, overwrite)
      when Kameleoon::PageView
        @data.add_page_view(data)
      when Kameleoon::DataManager::PageViewVisit
        @data.add_page_view_visit(data)
      when Kameleoon::Conversion
        @data.add_conversion(data)
      when Kameleoon::Cookie
        @data.cookie = data
      when Kameleoon::OperatingSystem
        @data.set_operating_system(data, overwrite)
      when Kameleoon::Geolocation
        @data.set_geolocation(data, overwrite)
      when Kameleoon::KcsHeat
        @data.kcs_heat = data
      when Kameleoon::VisitorVisits
        @data.visitor_visits = data
      when Kameleoon::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



207
208
209
210
211
# File 'lib/kameleoon/data/manager/visitor.rb', line 207

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

#browserObject



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

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

#cloneObject



213
214
215
# File 'lib/kameleoon/data/manager/visitor.rb', line 213

def clone
  Visitor.new(self)
end

#conversionsObject



154
155
156
157
158
# File 'lib/kameleoon/data/manager/visitor.rb', line 154

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


95
96
97
98
99
# File 'lib/kameleoon/data/manager/visitor.rb', line 95

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

#count_sendable_dataObject



53
54
55
56
57
58
59
60
# File 'lib/kameleoon/data/manager/visitor.rb', line 53

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



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

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



68
69
70
71
72
# File 'lib/kameleoon/data/manager/visitor.rb', line 68

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

#enumerate_sendable_data(&blk) ⇒ Object



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

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

#geolocationObject



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

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

#kcs_heatObject



101
102
103
104
105
# File 'lib/kameleoon/data/manager/visitor.rb', line 101

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



41
42
43
# File 'lib/kameleoon/data/manager/visitor.rb', line 41

def last_activity_time
  @data.last_activity_time
end


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

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


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

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

#mapping_identifierObject



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

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



130
131
132
133
134
135
136
137
138
139
# File 'lib/kameleoon/data/manager/visitor.rb', line 130

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



86
87
88
89
90
91
92
93
# File 'lib/kameleoon/data/manager/visitor.rb', line 86

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



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

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

#to_sObject



26
27
28
# File 'lib/kameleoon/data/manager/visitor.rb', line 26

def to_s
  'Visitor{}'
end

#update_last_activity_timeObject



45
46
47
# File 'lib/kameleoon/data/manager/visitor.rb', line 45

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

#user_agentObject



62
63
64
65
66
# File 'lib/kameleoon/data/manager/visitor.rb', line 62

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



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

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

#visitor_visitsObject



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

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