kameleoon-client-ruby 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 283250365ae9bf4087ebffeb7a4de0e31cca91f06a865cdd4ad2cae1f88c692c
4
- data.tar.gz: 31ab8ddbd1ef7524b41019a0afe442a47ee5b5e9e1d50649ed04aab625d7c3a3
3
+ metadata.gz: 92e73ac3d81e29ddfc093e8da1a47f42b9970ea6e8717e0752be511b759db17a
4
+ data.tar.gz: 710361f25b6338e35bb668bb30f116c931efddd21fdb272fa5367add4d82db22
5
5
  SHA512:
6
- metadata.gz: 23f61dd193ad1bb7477ee44e0e2eb5c16bec625748b9ebdde37a9a6b9e71a4610a98c218a4e76addb66a5a55ecf2bcae1764f2aac8d9f9f8ebb6bbc3be86e318
7
- data.tar.gz: d27d91e39fb5bc968ba414016642de07baef8ef7888f1d93969ae5fb67f07b903ba60b981de9387fa5c6eb20e99bd647d965fea0123841348f67a8aa66840f99
6
+ metadata.gz: 24db6ec9d63c160690506060d703661f77c5b60160fc585117b91460e74185a095f0b52156b268ba18d445797a584c9bd92e824c2bbecf8533d08e09cf89dab6
7
+ data.tar.gz: ab2f4e530b33235f7105158414ff77ce52f5b824632e4cae53ed06425f32be6f22719dcae86d7d5660cbd09ea4c090672ee5a237828a6db0e0772e80d65032c5
@@ -12,7 +12,7 @@ module Kameleoon
12
12
  def initialize(page_view, count = 1, timestamp = nil)
13
13
  @page_view = page_view
14
14
  @count = count
15
- @last_timestamp = timestamp != nil ? timestamp : Time.new.to_i
15
+ @last_timestamp = timestamp.nil? ? Time.new.to_i : timestamp
16
16
  end
17
17
 
18
18
  # Not thread-save method, should be called in synchronized code
@@ -20,10 +20,11 @@ module Kameleoon
20
20
  def overwrite(page_view)
21
21
  @page_view = page_view
22
22
  @count += 1
23
+ @last_timestamp = Time.new.to_i
23
24
  end
24
25
 
25
26
  # Not thread-save method, should be called in synchronized code
26
- def merge (page_view_visit)
27
+ def merge(page_view_visit)
27
28
  @count += page_view_visit.count
28
29
  @last_timestamp = [@last_timestamp, page_view_visit.last_timestamp].max
29
30
  end
@@ -24,7 +24,7 @@ module Kameleoon
24
24
  attr_reader :data, :is_unique_identifier
25
25
 
26
26
  def to_s
27
- "Visitor{}"
27
+ 'Visitor{}'
28
28
  end
29
29
 
30
30
  def initialize(source = nil)
@@ -52,7 +52,10 @@ module Kameleoon
52
52
 
53
53
  def count_sendable_data
54
54
  count_sendable_data = @data.count_sendable_data
55
- Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.count_sendable_data -> (count_sendable_data: %s)', count_sendable_data)
55
+ Logging::KameleoonLogger.debug(
56
+ 'CALL/RETURN: Visitor.count_sendable_data -> (count_sendable_data: %s)',
57
+ count_sendable_data
58
+ )
56
59
  count_sendable_data
57
60
  end
58
61
 
@@ -82,7 +85,10 @@ module Kameleoon
82
85
 
83
86
  def operating_system
84
87
  operating_system = @data.operating_system
85
- Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.operating_system -> (operating_system: %s)', operating_system)
88
+ Logging::KameleoonLogger.debug(
89
+ 'CALL/RETURN: Visitor.operating_system -> (operating_system: %s)',
90
+ operating_system
91
+ )
86
92
  operating_system
87
93
  end
88
94
 
@@ -122,7 +128,14 @@ module Kameleoon
122
128
  end
123
129
 
124
130
  def mapping_identifier=(value)
125
- @data.mapping_identifier = value
131
+ return unless @data.mapping_identifier.nil?
132
+
133
+ @data.mutex.with_write_lock do
134
+ if @data.mapping_identifier.nil?
135
+ @data.mapping_identifier = value
136
+ Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.mapping_identifier = %s', value)
137
+ end
138
+ end
126
139
  end
127
140
 
128
141
  def custom_data
@@ -83,6 +83,7 @@ module Kameleoon
83
83
  Logging::KameleoonLogger.log_level = Logging::LogLevel::INFO
84
84
  end
85
85
 
86
+ ObjectSpace.define_finalizer(self, method(:dispose))
86
87
  Logging::KameleoonLogger.info("RETURN: KameleoonClient.new(site_code: '%s', config: %s)",
87
88
  site_code, config)
88
89
  end
@@ -42,12 +42,20 @@ module Kameleoon
42
42
  filter = Types::RemoteVisitorDataFilter.new unless filter.is_a?(Types::RemoteVisitorDataFilter)
43
43
  is_unique_identifier = @visitor_manger.get_visitor(visitor_code)&.is_unique_identifier || false
44
44
  response = @network_manager.get_remote_visitor_data(visitor_code, filter, is_unique_identifier, timeout)
45
- (data_to_add, data_to_return) = parse_custom_data_array(visitor_code, response)
45
+ remote_visitor_data = parse_custom_data_array(visitor_code, response)
46
+ remote_visitor_data.mark_data_as_sent(@data_manager.data_file.custom_data_info)
47
+ data_to_add = remote_visitor_data.collect_data_to_add
46
48
  if add_data && !data_to_add.empty?
47
49
  # Cannot use `VisitorManager.add_data` because it could use remote visitor data for mapping.
48
50
  visitor = @visitor_manger.get_or_create_visitor(visitor_code)
49
51
  visitor.add_data(*data_to_add, overwrite: false)
50
52
  end
53
+ if filter.visitor_code && !remote_visitor_data.visitor_code.nil?
54
+ # We apply visitor code from the latest visit fetched from Data API
55
+ visitor = @visitor_manger.get_or_create_visitor(visitor_code)
56
+ visitor.mapping_identifier = remote_visitor_data.visitor_code
57
+ end
58
+ data_to_return = remote_visitor_data.collect_data_to_return
51
59
  Logging::KameleoonLogger.debug(
52
60
  "RETURN: RemoteDataManager.get_visitor_data(visitor_code: '%s', add_data: %s, filter: %s," \
53
61
  ' timeout: %s) -> (visitor_data: %s)',
@@ -59,9 +67,7 @@ module Kameleoon
59
67
  ##
60
68
  # helper method used by `get_remote_visitor_data`
61
69
  def parse_custom_data_array(visitor_code, response)
62
- remote_visitor_data = RemoteVisitorData.new(JSON.parse(response))
63
- remote_visitor_data.mark_data_as_sent(@data_manager.data_file.custom_data_info)
64
- [remote_visitor_data.collect_data_to_add, remote_visitor_data.collect_data_to_return]
70
+ RemoteVisitorData.new(JSON.parse(response))
65
71
  rescue StandardError => e
66
72
  Logging::KameleoonLogger.error("Parsing of remote visitor data of '#{visitor_code}' failed: #{e}")
67
73
  raise
@@ -16,7 +16,7 @@ module Kameleoon
16
16
  module RemoteData
17
17
  class RemoteVisitorData
18
18
  attr_reader :custom_data_dict, :page_view_visits, :conversions, :experiments, :device, :browser,
19
- :operating_system, :geolocation, :previous_visitor_visits, :kcs_heat
19
+ :operating_system, :geolocation, :previous_visitor_visits, :kcs_heat, :visitor_code
20
20
 
21
21
  def initialize(hash)
22
22
  current_visit = hash['currentVisit']
@@ -68,18 +68,20 @@ module Kameleoon
68
68
  private
69
69
 
70
70
  def parse_visit(hash)
71
+ @visitor_code = hash['visitorCode'] if @visitor_code.nil?
71
72
  custom_data_events = hash['customDataEvents']
72
- parse_custom_data(custom_data_events) if custom_data_events != nil && custom_data_events.size.positive?
73
+ parse_custom_data(custom_data_events) if !custom_data_events.nil? && custom_data_events.size.positive?
73
74
  page_events = hash['pageEvents']
74
- parse_pages(page_events) if page_events != nil && page_events.size.positive?
75
+ parse_pages(page_events) if !page_events.nil? && page_events.size.positive?
75
76
  experiment_events = hash['experimentEvents']
76
- parse_experiments(experiment_events) if experiment_events != nil && experiment_events.size.positive?
77
+ parse_experiments(experiment_events) if !experiment_events.nil? && experiment_events.size.positive?
77
78
  conversion_events = hash['conversionEvents']
78
- parse_conversions(conversion_events) if conversion_events != nil && conversion_events.size.positive?
79
+ parse_conversions(conversion_events) if !conversion_events.nil? && conversion_events.size.positive?
79
80
  geolocation_events = hash['geolocationEvents']
80
- @geolocation = parse_geolocation(geolocation_events) if @geolocation.nil? && geolocation_events != nil && geolocation_events.size.positive?
81
+ @geolocation = parse_geolocation(geolocation_events) if @geolocation.nil? && !geolocation_events.nil? && \
82
+ geolocation_events.size.positive?
81
83
  static_data_events = hash['staticDataEvent']
82
- parse_static_data(static_data_events) if static_data_events != nil
84
+ parse_static_data(static_data_events) unless static_data_events.nil?
83
85
  end
84
86
 
85
87
  def parse_custom_data(custom_data_events)
@@ -13,15 +13,17 @@ module Kameleoon
13
13
  super(json_condition, json_condition['title'])
14
14
  end
15
15
 
16
- def check(page_view_visit_storage)
17
- return false unless page_view_visit_storage.is_a?(Kameleoon::DataManager::DataMapStorage)
16
+ def check(page_view_visits)
17
+ return false unless page_view_visits.is_a?(Kameleoon::DataManager::DataMapStorage)
18
18
 
19
- is_targeted = false
20
- page_view_visit_storage.enumerate do |visit|
21
- is_targeted = visit.is_a?(Kameleoon::DataManager::PageViewVisit) && check_targeting(visit.page_view.title)
22
- break if is_targeted
19
+ latest = nil
20
+ page_view_visits.enumerate do |visit|
21
+ if visit.is_a?(Kameleoon::DataManager::PageViewVisit) \
22
+ && (latest.nil? || visit.last_timestamp > latest.last_timestamp)
23
+ latest = visit
24
+ end
23
25
  end
24
- is_targeted
26
+ !latest.nil? && latest.is_a?(Kameleoon::DataManager::PageViewVisit) && check_targeting(latest.page_view.title)
25
27
  end
26
28
  end
27
29
  end
@@ -13,22 +13,17 @@ module Kameleoon
13
13
  super(json_condition, json_condition['url'])
14
14
  end
15
15
 
16
- def check(page_view_visit_storage)
17
- return false unless page_view_visit_storage.is_a?(Kameleoon::DataManager::DataMapStorage)
18
- return !page_view_visit_storage.get(condition_value).nil? if operator == Operator::EXACT
16
+ def check(page_view_visits)
17
+ return false unless page_view_visits.is_a?(Kameleoon::DataManager::DataMapStorage)
19
18
 
20
- is_targeted = false
21
- page_view_visit_storage.enumerate do |visit|
22
- is_targeted = check_page_view_visit(visit)
23
- break if is_targeted
19
+ latest = nil
20
+ page_view_visits.enumerate do |visit|
21
+ if visit.is_a?(Kameleoon::DataManager::PageViewVisit) \
22
+ && (latest.nil? || visit.last_timestamp > latest.last_timestamp)
23
+ latest = visit
24
+ end
24
25
  end
25
- is_targeted
26
- end
27
-
28
- private
29
-
30
- def check_page_view_visit(visit)
31
- visit.is_a?(Kameleoon::DataManager::PageViewVisit) && check_targeting(visit.page_view.url)
26
+ !latest.nil? && latest.is_a?(Kameleoon::DataManager::PageViewVisit) && check_targeting(latest.page_view.url)
32
27
  end
33
28
  end
34
29
  end
@@ -5,7 +5,7 @@ module Kameleoon
5
5
  module Types
6
6
  class RemoteVisitorDataFilter
7
7
  attr_reader :previous_visit_amount, :current_visit, :custom_data, :page_views, :geolocation, :device, :browser,
8
- :operating_system, :conversions, :experiments, :kcs
8
+ :operating_system, :conversions, :experiments, :kcs, :visitor_code
9
9
 
10
10
  def to_s
11
11
  "RemoteVisitorDataFilter{previous_visit_amount:#{@previous_visit_amount}," \
@@ -17,13 +17,15 @@ module Kameleoon
17
17
  "browser:#{@browser}," \
18
18
  "operating_system:#{@operating_system}," \
19
19
  "conversions:#{@conversions}," \
20
- "experiments:#{@experiments},kcs:#{@kcs}}"
20
+ "experiments:#{@experiments}," \
21
+ "kcs:#{@kcs}," \
22
+ "visitor_code:#{@visitor_code}}"
21
23
  end
22
24
 
23
25
  def initialize(
24
26
  previous_visit_amount: 1, current_visit: true, custom_data: true, page_views: false,
25
27
  geolocation: false, device: false, browser: false, operating_system: false, conversions: false,
26
- experiments: false, kcs: false
28
+ experiments: false, kcs: false, visitor_code: true
27
29
  )
28
30
  @previous_visit_amount = previous_visit_amount
29
31
  @current_visit = current_visit
@@ -36,6 +38,7 @@ module Kameleoon
36
38
  @conversions = conversions
37
39
  @experiments = experiments
38
40
  @kcs = kcs
41
+ @visitor_code = visitor_code
39
42
  end
40
43
  end
41
44
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kameleoon
4
- SDK_VERSION = '3.5.0'
4
+ SDK_VERSION = '3.6.0'
5
5
  SDK_NAME = 'RUBY'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kameleoon-client-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kameleoon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-04 00:00:00.000000000 Z
11
+ date: 2024-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request