kameleoon-client-ruby 3.15.0 → 3.16.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 +4 -4
- data/lib/kameleoon/configuration/custom_data_info.rb +12 -3
- data/lib/kameleoon/data/custom_data.rb +51 -13
- data/lib/kameleoon/data/manager/visitor.rb +4 -2
- data/lib/kameleoon/data/manager/visitor_manager.rb +26 -15
- data/lib/kameleoon/data/mapping_identifier.rb +9 -2
- data/lib/kameleoon/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3df9ec4718c2a87cff0c2ad6344d43ca3ad095531badca20a6ac1bc0c1db9126
|
4
|
+
data.tar.gz: ba946333858defdeedccfdd3468aab44eeae80a8e9f4f407b68db4b4701a47bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d01c49dabf864637880c54117b74580d8b9f08567fe3755dbdaf3483e8da91e44c46041bfc537de1efb9bbcc969fdf106a273a235e4b933ccf85da74cafa00f2
|
7
|
+
data.tar.gz: 287fc1558d2f377db0cbe20b31069fa216bdffa5cc640286897895bb7a18903f2b1f706c1697c37ac1f1af0fe1e9b88a7beded87aaa056ec810ef571f77793d9
|
@@ -14,13 +14,18 @@ module Kameleoon
|
|
14
14
|
@local_only = Set[]
|
15
15
|
@visitor_scope = Set[]
|
16
16
|
@custom_data_index_by_id = {}
|
17
|
+
@custom_data_index_by_name = {}
|
17
18
|
unless hashes.nil?
|
18
19
|
for hash in hashes
|
19
20
|
index = hash['index']
|
20
21
|
@local_only.add(index) if hash['localOnly']
|
21
22
|
@visitor_scope.add(index) if hash['scope'] == SCOPE_VISITOR
|
22
|
-
|
23
|
-
|
23
|
+
if index
|
24
|
+
id = hash['id']
|
25
|
+
name = hash['name']
|
26
|
+
@custom_data_index_by_id[id] = index if id
|
27
|
+
@custom_data_index_by_name[name] = index if name
|
28
|
+
end
|
24
29
|
if hash['isMappingIdentifier']
|
25
30
|
unless @mapping_identifier_index.nil?
|
26
31
|
Logging::KameleoonLogger.warning('More than one mapping identifier is set. Undefined behavior ' \
|
@@ -48,8 +53,12 @@ module Kameleoon
|
|
48
53
|
@custom_data_index_by_id[custom_data_id]
|
49
54
|
end
|
50
55
|
|
56
|
+
def get_custom_data_index_by_name(custom_data_name)
|
57
|
+
@custom_data_index_by_name[custom_data_name]
|
58
|
+
end
|
59
|
+
|
51
60
|
def self.mapping_identifier?(custom_data_info, custom_data)
|
52
|
-
!custom_data_info.nil? && (custom_data.
|
61
|
+
!custom_data_info.nil? && (custom_data.index == custom_data_info.mapping_identifier_index) && \
|
53
62
|
!(custom_data.values.empty? || custom_data.values[0].empty?)
|
54
63
|
end
|
55
64
|
end
|
@@ -8,50 +8,88 @@ require_relative 'data'
|
|
8
8
|
module Kameleoon
|
9
9
|
# Represents any custom data for targeting conditions
|
10
10
|
class CustomData < DuplicationUnsafeData
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :index, :name, :values, :overwrite
|
12
12
|
|
13
13
|
def to_s
|
14
|
-
"CustomData{
|
14
|
+
"CustomData{index:#{@index},name:'#{@name}',values:#{@values},overwrite:#{@overwrite}}"
|
15
15
|
end
|
16
16
|
|
17
|
-
# @param [Integer]
|
17
|
+
# @param [Integer] index Index of the custom data
|
18
18
|
# @param [String] value Value of the custom data
|
19
19
|
# @param [Array] values Array of values of the custom data
|
20
|
+
# @param [Boolean] overwrite Flag to explicitly control how the values are stored and how they appear in reports
|
21
|
+
#
|
22
|
+
# @overload
|
23
|
+
# @param [String] name Custom Data name, can be used instead of Custom Data index
|
24
|
+
# @param [String] value Value of the custom data
|
25
|
+
# @param [Array] values Array of values of the custom data
|
26
|
+
# @param [Boolean] overwrite Flag to explicitly control how the values are stored and how they appear in reports
|
20
27
|
#
|
21
28
|
# @overload
|
22
29
|
# @param [Hash] hash Json value encoded in a hash.
|
23
30
|
# rubocop:disable Metrics/MethodLength
|
24
|
-
def initialize(arg0, *args)
|
31
|
+
def initialize(arg0, *args, overwrite: true)
|
25
32
|
super(DataType::CUSTOM)
|
26
33
|
if arg0.is_a?(Hash)
|
27
34
|
hash = arg0
|
28
|
-
|
29
|
-
|
35
|
+
index = hash['index'] || hash['id']
|
36
|
+
name = hash['name']
|
37
|
+
if index.nil? && name.nil?
|
38
|
+
raise Kameleoon::Exception::NotFound.new('index/id/name'), '"index/id/name" is mandatory'
|
39
|
+
end
|
30
40
|
|
31
|
-
@
|
41
|
+
@index = index || -1
|
42
|
+
@name = name
|
32
43
|
values = hash['values']
|
33
44
|
raise Kameleoon::Exception::NotFound.new('values'), '"values" is mandatory' if values.nil?
|
34
45
|
|
35
46
|
@values = values.is_a?(Array) ? values.dup : [values]
|
47
|
+
@overwrite = hash.fetch('overwrite', true)
|
36
48
|
else
|
37
|
-
|
49
|
+
case arg0
|
50
|
+
when Integer
|
51
|
+
@index = arg0
|
52
|
+
when String
|
53
|
+
@index = -1
|
54
|
+
@name = arg0
|
55
|
+
else
|
56
|
+
raise Kameleoon::Exception.new('Unexpected arg0 type'), 'Unexpected arg0 type'
|
57
|
+
end
|
38
58
|
@values = args
|
59
|
+
@overwrite = overwrite
|
39
60
|
end
|
40
61
|
|
41
|
-
return if @
|
62
|
+
return if @index.is_a?(Integer)
|
42
63
|
|
43
|
-
Logging::KameleoonLogger.warning("CustomData field '
|
44
|
-
@
|
64
|
+
Logging::KameleoonLogger.warning("CustomData field 'index' must be of 'Integer' type")
|
65
|
+
@index = @index.is_a?(String) ? @index.to_i : -1
|
45
66
|
end
|
46
67
|
# rubocop:enable Metrics/MethodLength
|
47
68
|
|
69
|
+
def named_to_indexed(index)
|
70
|
+
CustomData.new(
|
71
|
+
{
|
72
|
+
'index' => index,
|
73
|
+
'name' => @name,
|
74
|
+
'values' => @values,
|
75
|
+
'overwrite' => @overwrite
|
76
|
+
}
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# DEPRECATED. Please use `index` instead.
|
82
|
+
def id
|
83
|
+
@index
|
84
|
+
end
|
85
|
+
|
48
86
|
def obtain_full_post_text_line
|
49
87
|
str_values = JSON.generate(Hash[@values.collect { |k| [k, 1] }])
|
50
88
|
params = {
|
51
89
|
eventType: 'customData',
|
52
|
-
index: @
|
90
|
+
index: @index,
|
53
91
|
valuesCountMap: str_values,
|
54
|
-
overwrite:
|
92
|
+
overwrite: @overwrite,
|
55
93
|
nonce: nonce
|
56
94
|
}
|
57
95
|
Kameleoon::Network::UriHelper.encode_query(params)
|
@@ -243,6 +243,8 @@ module Kameleoon
|
|
243
243
|
Logging::KameleoonLogger.debug('CALL: Visitor.add_data(args: %s, overwrite: %s)', args, overwrite)
|
244
244
|
@data.mutex.with_write_lock do
|
245
245
|
args.each do |data|
|
246
|
+
next if data.nil?
|
247
|
+
|
246
248
|
case data
|
247
249
|
when UserAgent
|
248
250
|
@data.user_agent = data.value
|
@@ -417,8 +419,8 @@ module Kameleoon
|
|
417
419
|
|
418
420
|
def add_custom_data(custom_data, overwrite)
|
419
421
|
@custom_data_map ||= {}
|
420
|
-
if overwrite || !@custom_data_map.include?(custom_data.
|
421
|
-
@custom_data_map[custom_data.
|
422
|
+
if overwrite || !@custom_data_map.include?(custom_data.index)
|
423
|
+
@custom_data_map[custom_data.index] = custom_data
|
422
424
|
end
|
423
425
|
end
|
424
426
|
|
@@ -77,21 +77,8 @@ module Kameleoon
|
|
77
77
|
cdi = @data_manager.data_file.custom_data_info
|
78
78
|
args.size.times do |i|
|
79
79
|
custom_data = args[i]
|
80
|
-
|
81
|
-
|
82
|
-
# We shouldn't send custom data with local only type
|
83
|
-
custom_data.mark_as_sent if cdi.local_only?(custom_data.id)
|
84
|
-
# If mappingIdentifier is passed, we should link anonymous visitor with real unique userId.
|
85
|
-
# After authorization, customer must be able to continue work with userId, but hash for variation
|
86
|
-
# should be calculated based on anonymous visitor code, that's why set MappingIdentifier to visitor.
|
87
|
-
if Configuration::CustomDataInfo.mapping_identifier?(cdi, custom_data)
|
88
|
-
visitor.mapping_identifier = visitor_code
|
89
|
-
user_id = custom_data.values[0]
|
90
|
-
args[i] = MappingIdentifier.new(custom_data)
|
91
|
-
if visitor_code != user_id
|
92
|
-
@visitors[user_id] = visitor.clone
|
93
|
-
Logging::KameleoonLogger.info(-> { "Linked anonymous visitor '#{visitor_code}' with user '#{user_id}'" })
|
94
|
-
end
|
80
|
+
if custom_data.is_a?(Kameleoon::CustomData)
|
81
|
+
args[i] = process_custom_data(cdi, visitor_code, visitor, custom_data)
|
95
82
|
end
|
96
83
|
end
|
97
84
|
visitor.add_data(*args, overwrite: overwrite)
|
@@ -104,6 +91,30 @@ module Kameleoon
|
|
104
91
|
|
105
92
|
private
|
106
93
|
|
94
|
+
def process_custom_data(cdi, visitor_code, visitor, custom_data)
|
95
|
+
unless custom_data.name.nil?
|
96
|
+
cd_index = cdi.get_custom_data_index_by_name(custom_data.name)
|
97
|
+
return nil if cd_index.nil?
|
98
|
+
|
99
|
+
custom_data = custom_data.named_to_indexed(cd_index)
|
100
|
+
end
|
101
|
+
# We shouldn't send custom data with local only type
|
102
|
+
custom_data.mark_as_sent if cdi.local_only?(custom_data.index)
|
103
|
+
# If mappingIdentifier is passed, we should link anonymous visitor with real unique userId.
|
104
|
+
# After authorization, customer must be able to continue work with userId, but hash for variation
|
105
|
+
# should be calculated based on anonymous visitor code, that's why set MappingIdentifier to visitor.
|
106
|
+
if Configuration::CustomDataInfo.mapping_identifier?(cdi, custom_data)
|
107
|
+
visitor.mapping_identifier = visitor_code
|
108
|
+
user_id = custom_data.values[0]
|
109
|
+
custom_data = MappingIdentifier.new(custom_data)
|
110
|
+
if visitor_code != user_id
|
111
|
+
@visitors[user_id] = visitor.clone
|
112
|
+
Logging::KameleoonLogger.info(-> { "Linked anonymous visitor '#{visitor_code}' with user '#{user_id}'" })
|
113
|
+
end
|
114
|
+
end
|
115
|
+
custom_data
|
116
|
+
end
|
117
|
+
|
107
118
|
def purge
|
108
119
|
Logging::KameleoonLogger.debug('CALL: VisitorManager.purge')
|
109
120
|
expired_time = Time.new.to_i - @expiration_period
|
@@ -6,7 +6,14 @@ require 'kameleoon/network/uri_helper'
|
|
6
6
|
module Kameleoon
|
7
7
|
class MappingIdentifier < CustomData
|
8
8
|
def initialize(custom_data)
|
9
|
-
super(
|
9
|
+
super(
|
10
|
+
{
|
11
|
+
'index' => custom_data.index,
|
12
|
+
'name' => custom_data.name,
|
13
|
+
'values' => custom_data.values,
|
14
|
+
'overwrite' => custom_data.overwrite
|
15
|
+
}
|
16
|
+
)
|
10
17
|
end
|
11
18
|
|
12
19
|
def unsent
|
@@ -27,7 +34,7 @@ module Kameleoon
|
|
27
34
|
end
|
28
35
|
|
29
36
|
def to_s
|
30
|
-
"MappingIdentifier{
|
37
|
+
"MappingIdentifier{index:#{@index},name:'#{@name}',values:#{@values},overwrite:#{@overwrite}}"
|
31
38
|
end
|
32
39
|
end
|
33
40
|
end
|
data/lib/kameleoon/version.rb
CHANGED
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.
|
4
|
+
version: 3.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kameleoon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-http-request
|