Class: Kameleoon::Managers::Tracking::TrackingBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/managers/tracking/tracking_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(visitor_codes, data_file, visitor_manager, request_size_limit) ⇒ TrackingBuilder

Returns a new instance of TrackingBuilder.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kameleoon/managers/tracking/tracking_builder.rb', line 14

def initialize(visitor_codes, data_file, visitor_manager, request_size_limit)
  @visitor_codes = visitor_codes
  @data_file = data_file
  @visitor_manager = visitor_manager
  @request_size_limit = request_size_limit
  @built = false
  @total_size = 0
  # result
  @visitor_codes_to_send = []
  @visitor_codes_to_keep = []
  @tracking_lines = []
  @unsent_visitor_data = []
end

Instance Attribute Details

#tracking_linesObject (readonly)

Returns the value of attribute tracking_lines.



12
13
14
# File 'lib/kameleoon/managers/tracking/tracking_builder.rb', line 12

def tracking_lines
  @tracking_lines
end

#unsent_visitor_dataObject (readonly)

Returns the value of attribute unsent_visitor_data.



12
13
14
# File 'lib/kameleoon/managers/tracking/tracking_builder.rb', line 12

def unsent_visitor_data
  @unsent_visitor_data
end

#visitor_codes_to_keepObject (readonly)

Returns the value of attribute visitor_codes_to_keep.



12
13
14
# File 'lib/kameleoon/managers/tracking/tracking_builder.rb', line 12

def visitor_codes_to_keep
  @visitor_codes_to_keep
end

#visitor_codes_to_sendObject (readonly)

Returns the value of attribute visitor_codes_to_send.



12
13
14
# File 'lib/kameleoon/managers/tracking/tracking_builder.rb', line 12

def visitor_codes_to_send
  @visitor_codes_to_send
end

Instance Method Details

#buildObject

Not thread-safe



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kameleoon/managers/tracking/tracking_builder.rb', line 29

def build
  return if @built

  @visitor_codes.each do |visitor_code|
    if @total_size <= @request_size_limit
      visitor = @visitor_manager.get_visitor(visitor_code)
      is_consent_given = consent_given?(visitor)
      data = collect_tracking_data(visitor_code, visitor, is_consent_given)
      if !data.empty?
        log_visitor_track_sending(visitor_code, is_consent_given, data)
        @visitor_codes_to_send.push(visitor_code)
        @unsent_visitor_data.concat(data)
      else
        log_visitor_track_no_data(visitor_code, is_consent_given)
      end
    else
      @visitor_codes_to_keep.push(visitor_code)
    end
  end
  @built = true
end