kameleoon-client-ruby 3.2.0 → 3.4.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 +16 -8
- data/lib/kameleoon/configuration/data_file.rb +40 -17
- data/lib/kameleoon/configuration/feature_flag.rb +10 -0
- data/lib/kameleoon/configuration/rule.rb +4 -0
- data/lib/kameleoon/configuration/settings.rb +13 -8
- data/lib/kameleoon/configuration/variation_exposition.rb +4 -0
- data/lib/kameleoon/data/browser.rb +4 -0
- data/lib/kameleoon/data/conversion.rb +4 -0
- data/lib/kameleoon/data/cookie.rb +4 -0
- data/lib/kameleoon/data/custom_data.rb +11 -3
- data/lib/kameleoon/data/data.rb +30 -4
- data/lib/kameleoon/data/device.rb +4 -0
- data/lib/kameleoon/data/geolocation.rb +5 -0
- data/lib/kameleoon/data/kcs_heat.rb +16 -0
- data/lib/kameleoon/data/manager/assigned_variation.rb +5 -0
- data/lib/kameleoon/data/manager/data_array_storage.rb +7 -0
- data/lib/kameleoon/data/manager/data_map_storage.rb +7 -0
- data/lib/kameleoon/data/manager/page_view_visit.rb +4 -0
- data/lib/kameleoon/data/manager/visitor.rb +198 -67
- data/lib/kameleoon/data/manager/visitor_manager.rb +54 -17
- data/lib/kameleoon/data/mapping_identifier.rb +33 -0
- data/lib/kameleoon/data/operating_system.rb +4 -0
- data/lib/kameleoon/data/page_view.rb +6 -1
- data/lib/kameleoon/data/unique_identifier.rb +11 -0
- data/lib/kameleoon/data/user_agent.rb +4 -0
- data/lib/kameleoon/data/visitor_visits.rb +12 -1
- data/lib/kameleoon/hybrid/manager.rb +13 -4
- data/lib/kameleoon/kameleoon_client.rb +348 -146
- data/lib/kameleoon/kameleoon_client_config.rb +64 -17
- data/lib/kameleoon/kameleoon_client_factory.rb +15 -2
- data/lib/kameleoon/logging/default_logger.rb +20 -0
- data/lib/kameleoon/logging/kameleoon_logger.rb +77 -0
- data/lib/kameleoon/logging/logger.rb +12 -0
- data/lib/kameleoon/managers/data/data_manager.rb +36 -0
- data/lib/kameleoon/managers/remote_data/remote_data_manager.rb +33 -18
- data/lib/kameleoon/managers/remote_data/remote_visitor_data.rb +42 -16
- data/lib/kameleoon/managers/tracking/tracking_builder.rb +149 -0
- data/lib/kameleoon/managers/tracking/tracking_manager.rb +97 -0
- data/lib/kameleoon/managers/tracking/visitor_tracking_registry.rb +94 -0
- data/lib/kameleoon/managers/warehouse/warehouse_manager.rb +22 -5
- data/lib/kameleoon/network/access_token_source.rb +46 -14
- data/lib/kameleoon/network/cookie/cookie_manager.rb +45 -7
- data/lib/kameleoon/network/net_provider.rb +2 -3
- data/lib/kameleoon/network/network_manager.rb +16 -21
- data/lib/kameleoon/network/request.rb +14 -3
- data/lib/kameleoon/network/response.rb +4 -0
- data/lib/kameleoon/network/url_provider.rb +11 -10
- data/lib/kameleoon/real_time/real_time_configuration_service.rb +10 -11
- data/lib/kameleoon/sdk_version.rb +31 -0
- data/lib/kameleoon/targeting/condition.rb +6 -2
- data/lib/kameleoon/targeting/condition_factory.rb +3 -0
- data/lib/kameleoon/targeting/conditions/browser_condition.rb +3 -3
- data/lib/kameleoon/targeting/conditions/cookie_condition.rb +10 -10
- data/lib/kameleoon/targeting/conditions/geolocation_condition.rb +0 -1
- data/lib/kameleoon/targeting/conditions/kcs_heat_range_condition.rb +37 -0
- data/lib/kameleoon/targeting/conditions/number_condition.rb +4 -4
- data/lib/kameleoon/targeting/conditions/operating_system_condition.rb +1 -2
- data/lib/kameleoon/targeting/conditions/sdk_language_condition.rb +2 -1
- data/lib/kameleoon/targeting/conditions/segment_condition.rb +3 -3
- data/lib/kameleoon/targeting/conditions/string_value_condition.rb +2 -1
- data/lib/kameleoon/targeting/conditions/target_feature_flag_condition.rb +7 -11
- data/lib/kameleoon/targeting/conditions/time_elapsed_since_visit_condition.rb +1 -2
- data/lib/kameleoon/targeting/conditions/visit_number_today_condition.rb +4 -4
- data/lib/kameleoon/targeting/conditions/visit_number_total_condition.rb +5 -3
- data/lib/kameleoon/targeting/conditions/visitor_new_return_condition.rb +7 -6
- data/lib/kameleoon/targeting/models.rb +0 -14
- data/lib/kameleoon/targeting/targeting_manager.rb +37 -7
- data/lib/kameleoon/targeting/tree_builder.rb +10 -5
- data/lib/kameleoon/types/remote_visitor_data_filter.rb +21 -3
- data/lib/kameleoon/types/variable.rb +21 -0
- data/lib/kameleoon/types/variation.rb +22 -0
- data/lib/kameleoon/utils.rb +18 -0
- data/lib/kameleoon/version.rb +1 -27
- metadata +16 -2
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'kameleoon/client_readiness'
|
|
4
|
-
require 'kameleoon/
|
|
5
|
-
require 'kameleoon/
|
|
6
|
-
require 'kameleoon/
|
|
4
|
+
require 'kameleoon/configuration/feature_flag'
|
|
5
|
+
require 'kameleoon/configuration/variation'
|
|
6
|
+
require 'kameleoon/configuration/data_file'
|
|
7
7
|
require 'kameleoon/data/custom_data'
|
|
8
8
|
require 'kameleoon/data/user_agent'
|
|
9
9
|
require 'kameleoon/data/manager/assigned_variation'
|
|
10
10
|
require 'kameleoon/data/manager/visitor_manager'
|
|
11
|
-
require 'kameleoon/
|
|
12
|
-
require 'kameleoon/
|
|
13
|
-
require 'kameleoon/
|
|
11
|
+
require 'kameleoon/exceptions'
|
|
12
|
+
require 'kameleoon/hybrid/manager'
|
|
13
|
+
require 'kameleoon/managers/data/data_manager'
|
|
14
|
+
require 'kameleoon/managers/remote_data/remote_data_manager'
|
|
15
|
+
require 'kameleoon/managers/tracking/tracking_manager'
|
|
16
|
+
require 'kameleoon/managers/tracking/visitor_tracking_registry'
|
|
17
|
+
require 'kameleoon/managers/warehouse/warehouse_manager'
|
|
14
18
|
require 'kameleoon/network/access_token_source'
|
|
15
19
|
require 'kameleoon/network/activity_event'
|
|
16
20
|
require 'kameleoon/network/network_manager'
|
|
17
21
|
require 'kameleoon/network/url_provider'
|
|
18
22
|
require 'kameleoon/network/cookie/cookie_manager'
|
|
19
|
-
require 'kameleoon/managers/warehouse/warehouse_manager'
|
|
20
23
|
require 'kameleoon/real_time/real_time_configuration_service'
|
|
21
|
-
require 'kameleoon/hybrid/manager'
|
|
22
24
|
require 'kameleoon/storage/cache_factory'
|
|
23
|
-
require 'kameleoon/
|
|
25
|
+
require 'kameleoon/targeting/models'
|
|
26
|
+
require 'kameleoon/targeting/targeting_manager'
|
|
24
27
|
require 'rufus/scheduler'
|
|
25
28
|
require 'yaml'
|
|
26
29
|
require 'json'
|
|
@@ -43,32 +46,50 @@ module Kameleoon
|
|
|
43
46
|
def initialize(site_code, config)
|
|
44
47
|
raise Exception::SiteCodeIsEmpty, 'Provided site_sode is empty' if site_code&.empty? != false
|
|
45
48
|
|
|
49
|
+
Logging::KameleoonLogger.info("CALL: KameleoonClient.new(site_code: '%s', config: %s)",
|
|
50
|
+
site_code, config)
|
|
51
|
+
@scheduler = Rufus::Scheduler.new
|
|
46
52
|
@site_code = site_code
|
|
47
53
|
@config = config
|
|
48
54
|
@real_time_configuration_service = nil
|
|
49
55
|
@update_configuration_handler = nil
|
|
50
56
|
@fetch_configuration_update_job = nil
|
|
51
|
-
|
|
52
|
-
@
|
|
53
|
-
@
|
|
57
|
+
data_file = Configuration::DataFile.new(config.environment, nil)
|
|
58
|
+
@data_manager = Managers::Data::DataManager.new(data_file)
|
|
59
|
+
@visitor_manager = Kameleoon::DataManager::VisitorManager.new(
|
|
60
|
+
@data_manager, config.session_duration_second, @scheduler
|
|
61
|
+
)
|
|
62
|
+
@hybrid_manager = Hybrid::ManagerImpl.new(HYBRID_EXPIRATION_TIME)
|
|
54
63
|
@network_manager = Network::NetworkManager.new(
|
|
55
64
|
config.environment,
|
|
56
65
|
config.default_timeout_millisecond,
|
|
57
|
-
Network::AccessTokenSourceFactory.new(config.client_id, config.client_secret
|
|
58
|
-
Network::UrlProvider.new(site_code)
|
|
59
|
-
|
|
66
|
+
Network::AccessTokenSourceFactory.new(config.client_id, config.client_secret),
|
|
67
|
+
Network::UrlProvider.new(site_code)
|
|
68
|
+
)
|
|
69
|
+
@tracking_manager = Managers::Tracking::TrackingManager.new(
|
|
70
|
+
@data_manager, @network_manager, @visitor_manager, config.tracking_interval_second, @scheduler
|
|
60
71
|
)
|
|
61
|
-
@warehouse_manager = Managers::Warehouse::WarehouseManager.new(@network_manager, @visitor_manager
|
|
62
|
-
@remote_data_manager =
|
|
63
|
-
|
|
64
|
-
|
|
72
|
+
@warehouse_manager = Managers::Warehouse::WarehouseManager.new(@network_manager, @visitor_manager)
|
|
73
|
+
@remote_data_manager = Managers::RemoteData::RemoteDataManager.new(
|
|
74
|
+
@data_manager, @network_manager, @visitor_manager
|
|
75
|
+
)
|
|
76
|
+
@cookie_manager = Network::Cookie::CookieManager.new(@data_manager, config.top_level_domain)
|
|
65
77
|
@readiness = ClientReadiness.new
|
|
66
|
-
@targeting_manager =
|
|
67
|
-
|
|
78
|
+
@targeting_manager = Targeting::TargetingManager.new(@data_manager, @visitor_manager)
|
|
79
|
+
|
|
80
|
+
if @config.verbose_mode == true && Logging::KameleoonLogger.log_level == Logging::LogLevel::WARNING
|
|
81
|
+
Logging::KameleoonLogger.log_level = Logging::LogLevel::INFO
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
Logging::KameleoonLogger.info("RETURN: KameleoonClient.new(site_code: '%s', config: %s)",
|
|
85
|
+
site_code, config)
|
|
68
86
|
end
|
|
69
87
|
|
|
70
88
|
def wait_init
|
|
71
|
-
|
|
89
|
+
Logging::KameleoonLogger.info('CALL: KameleoonClient.wait_init')
|
|
90
|
+
result = @readiness.wait
|
|
91
|
+
Logging::KameleoonLogger.info('RETURN: KameleoonClient.wait_init -> (result: %s)', result)
|
|
92
|
+
result
|
|
72
93
|
end
|
|
73
94
|
|
|
74
95
|
##
|
|
@@ -98,14 +119,29 @@ module Kameleoon
|
|
|
98
119
|
# visitor_code = get_visitor_code(cookies, 'my-domaine.com')
|
|
99
120
|
#
|
|
100
121
|
def get_visitor_code(cookies, default_visitor_code = nil)
|
|
101
|
-
|
|
122
|
+
Logging::KameleoonLogger.info("CALL: KameleoonClient.get_visitor_code(cookies: %s, default_visitor_code: '%s')",
|
|
123
|
+
cookies, default_visitor_code)
|
|
124
|
+
visitor_code = @cookie_manager.get_or_add(cookies, default_visitor_code)
|
|
125
|
+
Logging::KameleoonLogger.info(
|
|
126
|
+
"RETURN: KameleoonClient.get_visitor_code(cookies: %s, default_visitor_code: '%s') -> (visitor_code: '%s')",
|
|
127
|
+
cookies, default_visitor_code, visitor_code
|
|
128
|
+
)
|
|
129
|
+
visitor_code
|
|
102
130
|
end
|
|
103
131
|
|
|
104
132
|
def set_legal_consent(visitor_code, consent, cookies = nil)
|
|
133
|
+
Logging::KameleoonLogger.info(
|
|
134
|
+
"CALL: KameleoonClient.set_legal_consent(visitor_code: '%s', consent: %s, cookies: %s)",
|
|
135
|
+
visitor_code, consent, cookies
|
|
136
|
+
)
|
|
105
137
|
Utils::VisitorCode.validate(visitor_code)
|
|
106
138
|
visitor = @visitor_manager.get_or_create_visitor(visitor_code)
|
|
107
139
|
visitor.legal_consent = consent
|
|
108
140
|
@cookie_manager.update(visitor_code, consent, cookies)
|
|
141
|
+
Logging::KameleoonLogger.info(
|
|
142
|
+
"RETURN: KameleoonClient.set_legal_consent(visitor_code: '%s', consent: %s, cookies: %s)",
|
|
143
|
+
visitor_code, consent, cookies
|
|
144
|
+
)
|
|
109
145
|
end
|
|
110
146
|
|
|
111
147
|
##
|
|
@@ -122,8 +158,14 @@ module Kameleoon
|
|
|
122
158
|
# @raise [Kameleoon::Exception::VisitorCodeInvalid] If the visitor code is empty or longer than 255 chars
|
|
123
159
|
#
|
|
124
160
|
def add_data(visitor_code, *args)
|
|
161
|
+
Logging::KameleoonLogger.info("CALL: KameleoonClient.add_data(visitor_code: '%s', args: %s)",
|
|
162
|
+
visitor_code, args)
|
|
125
163
|
Utils::VisitorCode.validate(visitor_code)
|
|
126
164
|
@visitor_manager.add_data(visitor_code, *args)
|
|
165
|
+
Logging::KameleoonLogger.info(
|
|
166
|
+
"RETURN: KameleoonClient.add_data(visitor_code: '%s', args: %s)",
|
|
167
|
+
visitor_code, args
|
|
168
|
+
)
|
|
127
169
|
end
|
|
128
170
|
|
|
129
171
|
##
|
|
@@ -138,15 +180,24 @@ module Kameleoon
|
|
|
138
180
|
# @param [String] visitor_code Visitor code
|
|
139
181
|
# @param [Integer] goal_id Id of the goal
|
|
140
182
|
# @param [Float] revenue Optional - Revenue of the conversion.
|
|
141
|
-
# @param [Bool] is_unique_identifier Parameter that specifies whether the visitorCode is a unique
|
|
142
|
-
# This field is optional.
|
|
183
|
+
# @param [Bool] is_unique_identifier(DEPRECATED) Parameter that specifies whether the visitorCode is a unique
|
|
184
|
+
# identifier. This field is optional.
|
|
143
185
|
#
|
|
144
186
|
# @raise [Kameleoon::Exception::VisitorCodeInvalid] If the visitor code is empty or longer than 255 chars
|
|
145
187
|
#
|
|
146
|
-
def track_conversion(visitor_code, goal_id, revenue = 0.0, is_unique_identifier:
|
|
188
|
+
def track_conversion(visitor_code, goal_id, revenue = 0.0, is_unique_identifier: nil)
|
|
189
|
+
Logging::KameleoonLogger.info(
|
|
190
|
+
"CALL: KameleoonClient.track_conversion(visitor_code: '%s', goal_id: %s, revenue: %s, is_unique_identifier: %s)",
|
|
191
|
+
visitor_code, goal_id, revenue, is_unique_identifier
|
|
192
|
+
)
|
|
147
193
|
Utils::VisitorCode.validate(visitor_code)
|
|
194
|
+
set_unique_identifier(visitor_code, is_unique_identifier) unless is_unique_identifier.nil?
|
|
148
195
|
add_data(visitor_code, Conversion.new(goal_id, revenue))
|
|
149
|
-
|
|
196
|
+
@tracking_manager.add_visitor_code(visitor_code)
|
|
197
|
+
Logging::KameleoonLogger.info(
|
|
198
|
+
"RETURN: KameleoonClient.track_conversion(visitor_code: '%s', goal_id: %s, revenue: %s, is_unique_identifier: %s)",
|
|
199
|
+
visitor_code, goal_id, revenue, is_unique_identifier
|
|
200
|
+
)
|
|
150
201
|
end
|
|
151
202
|
|
|
152
203
|
##
|
|
@@ -157,20 +208,44 @@ module Kameleoon
|
|
|
157
208
|
# With this method you can manually send it.
|
|
158
209
|
#
|
|
159
210
|
# @param [String] visitor_code Optional field - Visitor code, without visitor code it flush all of the data
|
|
160
|
-
# @param [Bool]
|
|
161
|
-
#
|
|
162
|
-
#
|
|
163
|
-
#
|
|
164
|
-
#
|
|
165
|
-
|
|
166
|
-
|
|
211
|
+
# @param [Bool] instant A boolean flag indicating whether the data should be sent instantly (`true`) or
|
|
212
|
+
# according to the scheduled tracking interval (`false`).
|
|
213
|
+
# @param [Bool] is_unique_identifier(DEPRECATED) Parameter that specifies whether the visitorCode is a unique
|
|
214
|
+
# identifier. This field is optional.
|
|
215
|
+
#
|
|
216
|
+
# @raise [Kameleoon::Exception::VisitorCodeInvalid] If the visitor code is not nil and is empty or
|
|
217
|
+
# longer than 255 chars
|
|
218
|
+
#
|
|
219
|
+
def flush(visitor_code = nil, instant: false, is_unique_identifier: nil)
|
|
220
|
+
Logging::KameleoonLogger.info(
|
|
221
|
+
"CALL: KameleoonClient.flush(visitor_code: '%s', instant: %s, is_unique_identifier: %s)",
|
|
222
|
+
visitor_code, instant, is_unique_identifier
|
|
223
|
+
)
|
|
167
224
|
if visitor_code.nil?
|
|
168
225
|
@visitor_manager.enumerate do |visitor_code, visitor|
|
|
169
|
-
|
|
226
|
+
has_unsent_data = false
|
|
227
|
+
visitor.enumerate_sendable_data do |data|
|
|
228
|
+
if data.unsent
|
|
229
|
+
has_unsent_data = true
|
|
230
|
+
next false
|
|
231
|
+
end
|
|
232
|
+
next true
|
|
233
|
+
end
|
|
234
|
+
@tracking_manager.add_visitor_code(visitor_code) if has_unsent_data
|
|
170
235
|
end
|
|
171
236
|
else
|
|
172
|
-
|
|
237
|
+
Utils::VisitorCode.validate(visitor_code)
|
|
238
|
+
set_unique_identifier(visitor_code, is_unique_identifier) unless is_unique_identifier.nil?
|
|
239
|
+
if instant
|
|
240
|
+
@tracking_manager.track_visitor(visitor_code)
|
|
241
|
+
else
|
|
242
|
+
@tracking_manager.add_visitor_code(visitor_code)
|
|
243
|
+
end
|
|
173
244
|
end
|
|
245
|
+
Logging::KameleoonLogger.info(
|
|
246
|
+
"RETURN: KameleoonClient.flush(visitor_code: '%s', instant: %s, is_unique_identifier: %s)",
|
|
247
|
+
visitor_code, instant, is_unique_identifier
|
|
248
|
+
)
|
|
174
249
|
end
|
|
175
250
|
|
|
176
251
|
##
|
|
@@ -186,20 +261,32 @@ module Kameleoon
|
|
|
186
261
|
#
|
|
187
262
|
# @param [String] visitor_code Unique identifier of the user. This field is mandatory.
|
|
188
263
|
# @param [String] feature_key Key of the feature flag you want to expose to a user. This field is mandatory.
|
|
189
|
-
# @param [Bool] is_unique_identifier Parameter that specifies whether the visitorCode is a unique
|
|
190
|
-
# This field is optional.
|
|
264
|
+
# @param [Bool] is_unique_identifier(DEPRECATED) Parameter that specifies whether the visitorCode is a unique
|
|
265
|
+
# identifier. This field is optional.
|
|
191
266
|
#
|
|
192
267
|
# @raise [Kameleoon::Exception::FeatureNotFound] Feature Flag isn't found in this configuration
|
|
193
268
|
# @raise [Kameleoon::Exception::VisitorCodeInvalid] If the visitor code is empty or longer than 255 chars
|
|
194
269
|
#
|
|
195
|
-
def feature_active?(visitor_code, feature_key, is_unique_identifier:
|
|
196
|
-
|
|
197
|
-
|
|
270
|
+
def feature_active?(visitor_code, feature_key, is_unique_identifier: nil)
|
|
271
|
+
Logging::KameleoonLogger.info(
|
|
272
|
+
"CALL: KameleoonClient.feature_active?(visitor_code: '%s', feature_key: '%s', is_unique_identifier: %s)",
|
|
273
|
+
visitor_code, feature_key, is_unique_identifier
|
|
274
|
+
)
|
|
275
|
+
Utils::VisitorCode.validate(visitor_code)
|
|
276
|
+
set_unique_identifier(visitor_code, is_unique_identifier) unless is_unique_identifier.nil?
|
|
277
|
+
_, variation_key = _get_feature_variation_key(visitor_code, feature_key)
|
|
278
|
+
feature_active = variation_key != Kameleoon::Configuration::VariationType::VARIATION_OFF
|
|
279
|
+
Logging::KameleoonLogger.info(
|
|
280
|
+
"RETURN: KameleoonClient.feature_active?(visitor_code: '%s', feature_key: '%s', is_unique_identifier: %s) " \
|
|
281
|
+
'-> (feature_active: false)', visitor_code, feature_key, is_unique_identifier
|
|
282
|
+
)
|
|
283
|
+
feature_active
|
|
198
284
|
rescue Exception::FeatureEnvironmentDisabled
|
|
285
|
+
Logging::KameleoonLogger.debug('Feature environment disabled')
|
|
199
286
|
false
|
|
200
287
|
end
|
|
201
288
|
|
|
202
|
-
|
|
289
|
+
##
|
|
203
290
|
# get_feature_variation_key returns a variation key for visitor code
|
|
204
291
|
#
|
|
205
292
|
# This method takes a visitorCode and featureKey as mandatory arguments and
|
|
@@ -210,16 +297,28 @@ module Kameleoon
|
|
|
210
297
|
#
|
|
211
298
|
# @param [String] visitor_code
|
|
212
299
|
# @param [String] feature_key
|
|
213
|
-
# @param [Bool] is_unique_identifier Parameter that specifies whether the visitorCode is a unique
|
|
214
|
-
# This field is optional.
|
|
300
|
+
# @param [Bool] is_unique_identifier(DEPRECATED) Parameter that specifies whether the visitorCode is a unique
|
|
301
|
+
# identifier. This field is optional.
|
|
215
302
|
#
|
|
216
303
|
# @raise [Kameleoon::Exception::FeatureNotFound] Feature Flag isn't found in this configuration
|
|
217
304
|
# @raise [Kameleoon::Exception::VisitorCodeInvalid] If the visitor code is empty or longer than 255 chars
|
|
218
305
|
# @raise [Kameleoon::Exception::FeatureEnvironmentDisabled] If the requested feature flag is disabled for
|
|
219
306
|
# the current environment
|
|
220
307
|
#
|
|
221
|
-
def get_feature_variation_key(visitor_code, feature_key, is_unique_identifier:
|
|
222
|
-
|
|
308
|
+
def get_feature_variation_key(visitor_code, feature_key, is_unique_identifier: nil)
|
|
309
|
+
Logging::KameleoonLogger.info(
|
|
310
|
+
"CALL: KameleoonClient.get_feature_variation_key(visitor_code: '%s', feature_key: '%s', " \
|
|
311
|
+
'is_unique_identifier: %s)',
|
|
312
|
+
visitor_code, feature_key, is_unique_identifier
|
|
313
|
+
)
|
|
314
|
+
Utils::VisitorCode.validate(visitor_code)
|
|
315
|
+
set_unique_identifier(visitor_code, is_unique_identifier) unless is_unique_identifier.nil?
|
|
316
|
+
_, variation_key = _get_feature_variation_key(visitor_code, feature_key)
|
|
317
|
+
Logging::KameleoonLogger.info(
|
|
318
|
+
"RETURN: KameleoonClient.get_feature_variation_key(visitor_code: '%s', feature_key: '%s', " \
|
|
319
|
+
"is_unique_identifier: %s) -> (variation_key: '%s')",
|
|
320
|
+
visitor_code, feature_key, is_unique_identifier, variation_key
|
|
321
|
+
)
|
|
223
322
|
variation_key
|
|
224
323
|
end
|
|
225
324
|
|
|
@@ -231,8 +330,8 @@ module Kameleoon
|
|
|
231
330
|
# @param [String] visitor_code
|
|
232
331
|
# @param [String] feature_key
|
|
233
332
|
# @param [String] variable_name
|
|
234
|
-
# @param [Bool] is_unique_identifier Parameter that specifies whether the visitorCode is a unique
|
|
235
|
-
# This field is optional.
|
|
333
|
+
# @param [Bool] is_unique_identifier(DEPRECATED) Parameter that specifies whether the visitorCode is a unique
|
|
334
|
+
# identifier. This field is optional.
|
|
236
335
|
#
|
|
237
336
|
# @raise [Kameleoon::Exception::FeatureNotFound] Feature Flag isn't found in this configuration
|
|
238
337
|
# @raise [Kameleoon::Exception::FeatureVariableNotFound]
|
|
@@ -240,15 +339,27 @@ module Kameleoon
|
|
|
240
339
|
# @raise [Kameleoon::Exception::FeatureEnvironmentDisabled] If the requested feature flag is disabled for
|
|
241
340
|
# the current environment
|
|
242
341
|
#
|
|
243
|
-
def get_feature_variable(visitor_code, feature_key, variable_name, is_unique_identifier:
|
|
244
|
-
|
|
342
|
+
def get_feature_variable(visitor_code, feature_key, variable_name, is_unique_identifier: nil)
|
|
343
|
+
Logging::KameleoonLogger.info(
|
|
344
|
+
"CALL: KameleoonClient.get_feature_variable(visitor_code: '%s', feature_key: '%s', variable_name: '%s', " \
|
|
345
|
+
'is_unique_identifier: %s)', visitor_code, feature_key, variable_name, is_unique_identifier
|
|
346
|
+
)
|
|
347
|
+
Utils::VisitorCode.validate(visitor_code)
|
|
348
|
+
set_unique_identifier(visitor_code, is_unique_identifier) unless is_unique_identifier.nil?
|
|
349
|
+
feature_flag, variation_key = _get_feature_variation_key(visitor_code, feature_key)
|
|
245
350
|
variation = feature_flag.get_variation_key(variation_key)
|
|
246
351
|
variable = variation&.get_variable_by_key(variable_name)
|
|
247
352
|
if variable.nil?
|
|
248
353
|
raise Exception::FeatureVariableNotFound.new(variable_name),
|
|
249
354
|
"Feature variable #{variable_name} not found"
|
|
250
355
|
end
|
|
251
|
-
_parse_feature_variable(variable)
|
|
356
|
+
value = _parse_feature_variable(variable)
|
|
357
|
+
Logging::KameleoonLogger.info(
|
|
358
|
+
"RETURN: KameleoonClient.get_feature_variable(visitor_code: '%s', feature_key: '%s', variable_name: '%s', " \
|
|
359
|
+
'is_unique_identifier: %s) -> (variable: %s)',
|
|
360
|
+
visitor_code, feature_key, variable_name, is_unique_identifier, value
|
|
361
|
+
)
|
|
362
|
+
value
|
|
252
363
|
end
|
|
253
364
|
|
|
254
365
|
##
|
|
@@ -266,7 +377,11 @@ module Kameleoon
|
|
|
266
377
|
# @raise [Kameleoon::Exception::FeatureEnvironmentDisabled]
|
|
267
378
|
#
|
|
268
379
|
def get_feature_variation_variables(feature_key, variation_key)
|
|
269
|
-
|
|
380
|
+
Logging::KameleoonLogger.info(
|
|
381
|
+
"CALL: KameleoonClient.get_feature_variation_variables(feature_key: '%s', variation_key: '%s')",
|
|
382
|
+
feature_key, variation_key
|
|
383
|
+
)
|
|
384
|
+
feature_flag = @data_manager.data_file.get_feature_flag(feature_key)
|
|
270
385
|
variation = feature_flag.get_variation_key(variation_key)
|
|
271
386
|
if variation.nil?
|
|
272
387
|
raise Exception::FeatureVariationNotFound.new(variation_key),
|
|
@@ -274,6 +389,10 @@ module Kameleoon
|
|
|
274
389
|
end
|
|
275
390
|
variables = {}
|
|
276
391
|
variation.variables.each { |var| variables[var.key] = _parse_feature_variable(var) }
|
|
392
|
+
Logging::KameleoonLogger.info(
|
|
393
|
+
"RETURN: KameleoonClient.get_feature_variation_variables(feature_key: '%s', variation_key: '%s') " \
|
|
394
|
+
'-> (variables: %s)', feature_key, variation_key, variables
|
|
395
|
+
)
|
|
277
396
|
variables
|
|
278
397
|
end
|
|
279
398
|
|
|
@@ -290,7 +409,14 @@ module Kameleoon
|
|
|
290
409
|
#
|
|
291
410
|
# @return [Hash] Hash object of the json object.
|
|
292
411
|
def get_remote_data(key, timeout = @default_timeout)
|
|
293
|
-
|
|
412
|
+
Logging::KameleoonLogger.info("CALL: KameleoonClient.get_remote_data(key: '%s', timeout: %s)",
|
|
413
|
+
key, timeout)
|
|
414
|
+
remote_data = @remote_data_manager.get_data(key, timeout)
|
|
415
|
+
Logging::KameleoonLogger.info(
|
|
416
|
+
"RETURN: KameleoonClient.get_remote_data(key: '%s', timeout: %s) -> (remote_data: %s)",
|
|
417
|
+
key, timeout, remote_data
|
|
418
|
+
)
|
|
419
|
+
remote_data
|
|
294
420
|
end
|
|
295
421
|
|
|
296
422
|
##
|
|
@@ -304,12 +430,24 @@ module Kameleoon
|
|
|
304
430
|
# for a visitor. If not specified, the default value is `True`. This field is optional.
|
|
305
431
|
# @param [Integer] timeout Timeout for request (in milliseconds). Equals default_timeout in a config file.
|
|
306
432
|
# This field is optional.
|
|
307
|
-
# @param [Bool] is_unique_identifier Parameter that specifies whether the visitorCode is a unique
|
|
308
|
-
# This field is optional.
|
|
433
|
+
# @param [Bool] is_unique_identifier(DEPRECATED) Parameter that specifies whether the visitorCode is a unique
|
|
434
|
+
# identifier. This field is optional.
|
|
309
435
|
#
|
|
310
436
|
# @return [Array] An array of data assigned to the given visitor.
|
|
311
|
-
|
|
312
|
-
|
|
437
|
+
#
|
|
438
|
+
def get_remote_visitor_data(visitor_code, timeout = nil, add_data: true, filter: nil, is_unique_identifier: nil)
|
|
439
|
+
Logging::KameleoonLogger.info(
|
|
440
|
+
"CALL: KameleoonClient.get_remote_visitor_data(visitor_code: '%s', timeout: %s, add_data: %s, " \
|
|
441
|
+
'filter: %s, is_unique_identifier: %s)', visitor_code, timeout, add_data, filter, is_unique_identifier
|
|
442
|
+
)
|
|
443
|
+
set_unique_identifier(visitor_code, is_unique_identifier) unless is_unique_identifier.nil?
|
|
444
|
+
visitor_data = @remote_data_manager.get_visitor_data(visitor_code, add_data, filter, timeout)
|
|
445
|
+
Logging::KameleoonLogger.info(
|
|
446
|
+
"RETURN: KameleoonClient.get_remote_visitor_data(visitor_code: '%s', timeout: %s, add_data: %s, " \
|
|
447
|
+
'filter: %s, is_unique_identifier: %s) -> (visitor_data: %s)',
|
|
448
|
+
visitor_code, timeout, add_data, filter, is_unique_identifier, visitor_data
|
|
449
|
+
)
|
|
450
|
+
visitor_data
|
|
313
451
|
end
|
|
314
452
|
|
|
315
453
|
##
|
|
@@ -336,7 +474,18 @@ module Kameleoon
|
|
|
336
474
|
#
|
|
337
475
|
# @return [Kameleoon::CustomData] A `CustomData` instance confirming that the data has been added to the visitor.
|
|
338
476
|
def get_visitor_warehouse_audience(visitor_code, custom_data_index, timeout = nil, warehouse_key: nil)
|
|
339
|
-
|
|
477
|
+
Logging::KameleoonLogger.info(
|
|
478
|
+
"CALL: KameleoonClient.get_visitor_warehouse_audience(visitor_code: '%s', custom_data_index: %s, " \
|
|
479
|
+
"timeout: %s, warehouse_key: '%s')", visitor_code, custom_data_index, timeout, warehouse_key
|
|
480
|
+
)
|
|
481
|
+
warehouse_audience = @warehouse_manager.get_visitor_warehouse_audience(visitor_code,
|
|
482
|
+
custom_data_index, warehouse_key, timeout)
|
|
483
|
+
Logging::KameleoonLogger.info(
|
|
484
|
+
"RETURN: KameleoonClient.get_visitor_warehouse_audience(visitor_code: '%s', custom_data_index: %s, " \
|
|
485
|
+
"timeout: %s, warehouse_key: '%s') -> (warehouse_audience: %s)",
|
|
486
|
+
visitor_code, custom_data_index, timeout, warehouse_key, warehouse_audience
|
|
487
|
+
)
|
|
488
|
+
warehouse_audience
|
|
340
489
|
end
|
|
341
490
|
|
|
342
491
|
##
|
|
@@ -344,7 +493,10 @@ module Kameleoon
|
|
|
344
493
|
#
|
|
345
494
|
# @return [Array] array of all feature flag keys
|
|
346
495
|
def get_feature_list # rubocop:disable Naming/AccessorMethodName
|
|
347
|
-
|
|
496
|
+
Logging::KameleoonLogger.info('CALL: KameleoonClient.get_feature_list')
|
|
497
|
+
features = @data_manager.data_file.feature_flags.keys
|
|
498
|
+
Logging::KameleoonLogger.info('RETURN: KameleoonClient.get_feature_list -> (features: %s)', features)
|
|
499
|
+
features
|
|
348
500
|
end
|
|
349
501
|
|
|
350
502
|
##
|
|
@@ -353,19 +505,77 @@ module Kameleoon
|
|
|
353
505
|
# @raise [Kameleoon::Exception::VisitorCodeInvalid] If the visitor code is empty or longer than 255 chars
|
|
354
506
|
#
|
|
355
507
|
# @return [Array] array of active feature flag keys for a visitor
|
|
508
|
+
#
|
|
509
|
+
# DEPRECATED. Please use `get_active_features` instead.
|
|
356
510
|
def get_active_feature_list_for_visitor(visitor_code)
|
|
511
|
+
Logging::KameleoonLogger.warning('[DEPRECATION] `get_active_feature_list_for_visitor` is deprecated.' \
|
|
512
|
+
' Please use `get_active_features` instead.')
|
|
513
|
+
Logging::KameleoonLogger.info("CALL: KameleoonClient.get_active_feature_list_for_visitor(visitor_code: '%s')",
|
|
514
|
+
visitor_code)
|
|
357
515
|
Utils::VisitorCode.validate(visitor_code)
|
|
358
516
|
list_keys = []
|
|
359
|
-
@data_file.feature_flags.each do |feature_key, feature_flag|
|
|
517
|
+
@data_manager.data_file.feature_flags.each do |feature_key, feature_flag|
|
|
360
518
|
next unless feature_flag.environment_enabled
|
|
361
519
|
|
|
362
520
|
variation, rule, = _calculate_variation_key_for_feature(visitor_code, feature_flag)
|
|
363
521
|
variation_key = _get_variation_key(variation, rule, feature_flag)
|
|
364
522
|
list_keys.push(feature_key) if variation_key != Kameleoon::Configuration::VariationType::VARIATION_OFF
|
|
365
523
|
end
|
|
524
|
+
Logging::KameleoonLogger.info(
|
|
525
|
+
"RETURN: KameleoonClient.get_active_feature_list_for_visitor(visitor_code: '%s') -> (features: %s)",
|
|
526
|
+
visitor_code, list_keys
|
|
527
|
+
)
|
|
366
528
|
list_keys
|
|
367
529
|
end
|
|
368
530
|
|
|
531
|
+
##
|
|
532
|
+
# Returns a Hash that contains the assigned variations of the active features using the keys
|
|
533
|
+
# of the corresponding active features.
|
|
534
|
+
#
|
|
535
|
+
# @param [String] visitor_code unique identifier of a visitor.
|
|
536
|
+
#
|
|
537
|
+
# @raise [Kameleoon::Exception::VisitorCodeInvalid] If the visitor code is empty or longer than 255 chars or is nil
|
|
538
|
+
#
|
|
539
|
+
# @return [Hash] Hash of active features for a visitor
|
|
540
|
+
def get_active_features(visitor_code)
|
|
541
|
+
Logging::KameleoonLogger.info("CALL: KameleoonClient.get_active_features(visitor_code: '%s')", visitor_code)
|
|
542
|
+
Utils::VisitorCode.validate(visitor_code)
|
|
543
|
+
map_active_features = {}
|
|
544
|
+
|
|
545
|
+
@data_manager.data_file.feature_flags.each_value do |feature_flag|
|
|
546
|
+
next unless feature_flag.environment_enabled
|
|
547
|
+
|
|
548
|
+
var_by_exp, rule = _calculate_variation_key_for_feature(visitor_code, feature_flag)
|
|
549
|
+
variation_key = _get_variation_key(var_by_exp, rule, feature_flag)
|
|
550
|
+
|
|
551
|
+
next if variation_key == Configuration::VariationType::VARIATION_OFF
|
|
552
|
+
|
|
553
|
+
variation = feature_flag.get_variation_key(variation_key)
|
|
554
|
+
variables = {}
|
|
555
|
+
|
|
556
|
+
variation&.variables&.each do |variable|
|
|
557
|
+
variables[variable.key] = Kameleoon::Types::Variable.new(
|
|
558
|
+
variable.key,
|
|
559
|
+
variable.type,
|
|
560
|
+
_parse_feature_variable(variable)
|
|
561
|
+
)
|
|
562
|
+
end
|
|
563
|
+
|
|
564
|
+
variables.freeze
|
|
565
|
+
map_active_features[feature_flag.feature_key] = Kameleoon::Types::Variation.new(
|
|
566
|
+
variation_key,
|
|
567
|
+
var_by_exp ? var_by_exp.variation_id : nil,
|
|
568
|
+
rule ? rule.experiment_id : nil,
|
|
569
|
+
variables
|
|
570
|
+
)
|
|
571
|
+
end
|
|
572
|
+
|
|
573
|
+
map_active_features.freeze
|
|
574
|
+
Logging::KameleoonLogger.info("RETURN: KameleoonClient.get_active_features(visitor_code: '%s') -> (features: %s)",
|
|
575
|
+
visitor_code, map_active_features)
|
|
576
|
+
map_active_features
|
|
577
|
+
end
|
|
578
|
+
|
|
369
579
|
##
|
|
370
580
|
# The `on_update_configuration()` method allows you to handle the event when configuration
|
|
371
581
|
# has updated data. It takes one input parameter: callable **handler**. The handler
|
|
@@ -374,6 +584,7 @@ module Kameleoon
|
|
|
374
584
|
# @param handler [Callable | NilClass] The handler that will be called when the configuration
|
|
375
585
|
# is updated using a real-time configuration event.
|
|
376
586
|
def on_update_configuration(handler)
|
|
587
|
+
Logging::KameleoonLogger.info('CALL/RETURN: KameleoonClient.on_update_configuration(handler)')
|
|
377
588
|
@update_configuration_handler = handler
|
|
378
589
|
end
|
|
379
590
|
|
|
@@ -386,8 +597,14 @@ module Kameleoon
|
|
|
386
597
|
# @return [String] JavasScript code to be inserted in your page to send automatically
|
|
387
598
|
# the exposure events to the analytics solution you are using.
|
|
388
599
|
def get_engine_tracking_code(visitor_code)
|
|
600
|
+
Logging::KameleoonLogger.info("CALL: KameleoonClient.get_engine_tracking_code(visitor_code: '%s')", visitor_code)
|
|
389
601
|
visitor_variations = @visitor_manager.get_visitor(visitor_code)&.variations
|
|
390
|
-
@hybrid_manager.get_engine_tracking_code(visitor_variations)
|
|
602
|
+
engine_tracking_code = @hybrid_manager.get_engine_tracking_code(visitor_variations)
|
|
603
|
+
Logging::KameleoonLogger.info(
|
|
604
|
+
"RETURN: KameleoonClient.get_engine_tracking_code(visitor_code: '%s') -> (engine_tracking_code: '%s')",
|
|
605
|
+
visitor_code, engine_tracking_code
|
|
606
|
+
)
|
|
607
|
+
engine_tracking_code
|
|
391
608
|
end
|
|
392
609
|
|
|
393
610
|
private
|
|
@@ -395,17 +612,17 @@ module Kameleoon
|
|
|
395
612
|
HYBRID_EXPIRATION_TIME = 5
|
|
396
613
|
|
|
397
614
|
def fetch_configuration_initially
|
|
398
|
-
|
|
615
|
+
Logging::KameleoonLogger.info('Initial configuration fetch is started.')
|
|
399
616
|
Thread.new do
|
|
400
617
|
ok = false
|
|
401
618
|
begin
|
|
402
619
|
ok = obtain_configuration
|
|
403
|
-
|
|
620
|
+
Logging::KameleoonLogger.error('Initial configuration fetch failed') unless ok
|
|
404
621
|
rescue StandardError => e
|
|
405
|
-
|
|
622
|
+
Logging::KameleoonLogger.error('Initial configuration fetch failed: %s', e)
|
|
406
623
|
end
|
|
407
624
|
@readiness.set(ok)
|
|
408
|
-
manage_configuration_update(@data_file.settings.real_time_update) if ok
|
|
625
|
+
manage_configuration_update(@data_manager.data_file.settings.real_time_update) if ok
|
|
409
626
|
end
|
|
410
627
|
end
|
|
411
628
|
|
|
@@ -415,21 +632,23 @@ module Kameleoon
|
|
|
415
632
|
begin
|
|
416
633
|
ok = obtain_configuration(time_stamp)
|
|
417
634
|
rescue StandardError => e
|
|
418
|
-
|
|
635
|
+
Logging::KameleoonLogger.error('Error occurred during configuration fetching: %s', e)
|
|
419
636
|
end
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
637
|
+
real_time_update = @data_manager.data_file.settings.real_time_update
|
|
638
|
+
if !ok && real_time_update
|
|
639
|
+
@data_manager.data_file.settings.real_time_update = false
|
|
640
|
+
real_time_update = false
|
|
641
|
+
Logging::KameleoonLogger.warning('Switching to polling mode due to failed fetch')
|
|
423
642
|
end
|
|
424
|
-
manage_configuration_update(
|
|
643
|
+
manage_configuration_update(real_time_update)
|
|
425
644
|
end
|
|
426
645
|
end
|
|
427
646
|
|
|
428
647
|
def start_configuration_update_job_if_needed
|
|
429
648
|
return unless @fetch_configuration_update_job.nil?
|
|
430
649
|
|
|
431
|
-
@fetch_configuration_update_job =
|
|
432
|
-
|
|
650
|
+
@fetch_configuration_update_job = @scheduler.schedule_every @config.refresh_interval_second do
|
|
651
|
+
Logging::KameleoonLogger.info('Scheduled job to fetch configuration is started.')
|
|
433
652
|
fetch_configuration_job
|
|
434
653
|
end
|
|
435
654
|
end
|
|
@@ -437,9 +656,9 @@ module Kameleoon
|
|
|
437
656
|
def stop_configuration_update_job_if_needed
|
|
438
657
|
return if @fetch_configuration_update_job.nil?
|
|
439
658
|
|
|
440
|
-
@fetch_configuration_update_job
|
|
659
|
+
@fetch_configuration_update_job&.unschedule
|
|
441
660
|
@fetch_configuration_update_job = nil
|
|
442
|
-
|
|
661
|
+
Logging::KameleoonLogger.info('Scheduled job to fetch configuration is stopped.')
|
|
443
662
|
end
|
|
444
663
|
|
|
445
664
|
def start_real_time_configuration_service_if_needed
|
|
@@ -448,13 +667,11 @@ module Kameleoon
|
|
|
448
667
|
url = @network_manager.url_provider.make_real_time_url
|
|
449
668
|
fetch_func = proc { |real_time_event| fetch_configuration_job(real_time_event.time_stamp) }
|
|
450
669
|
@real_time_configuration_service =
|
|
451
|
-
Kameleoon::RealTime::RealTimeConfigurationService.new(url, fetch_func
|
|
670
|
+
Kameleoon::RealTime::RealTimeConfigurationService.new(url, fetch_func)
|
|
452
671
|
end
|
|
453
672
|
|
|
454
673
|
def stop_real_time_configuration_service_if_needed
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
@real_time_configuration_service.close
|
|
674
|
+
@real_time_configuration_service&.close
|
|
458
675
|
@real_time_configuration_service = nil
|
|
459
676
|
end
|
|
460
677
|
|
|
@@ -483,24 +700,23 @@ module Kameleoon
|
|
|
483
700
|
# end
|
|
484
701
|
|
|
485
702
|
def obtain_configuration(time_stamp = nil)
|
|
486
|
-
|
|
703
|
+
Logging::KameleoonLogger.info('Fetching configuration from Client-Config service')
|
|
487
704
|
response = @network_manager.fetch_configuration(time_stamp)
|
|
488
705
|
return false unless response
|
|
489
706
|
|
|
490
707
|
configuration = JSON.parse(response)
|
|
491
|
-
|
|
492
|
-
apply_new_configuration(
|
|
708
|
+
data_file = Configuration::DataFile.new(@config.environment, configuration)
|
|
709
|
+
apply_new_configuration(data_file)
|
|
493
710
|
call_update_handler_if_needed(!time_stamp.nil?)
|
|
494
|
-
|
|
711
|
+
Logging::KameleoonLogger.info('Feature flags are fetched: %s', response.inspect)
|
|
495
712
|
true
|
|
496
713
|
end
|
|
497
714
|
|
|
498
715
|
def apply_new_configuration(data_file)
|
|
499
|
-
|
|
500
|
-
|
|
716
|
+
Logging::KameleoonLogger.debug('CALL: KameleoonClient.apply_new_configuration(data_file: %s)', data_file)
|
|
717
|
+
@data_manager.data_file = data_file
|
|
501
718
|
@network_manager.url_provider.apply_data_api_domain(data_file.settings.data_api_domain)
|
|
502
|
-
|
|
503
|
-
@visitor_manager.custom_data_info = data_file.custom_data_info
|
|
719
|
+
Logging::KameleoonLogger.debug('RETURN: KameleoonClient.apply_new_configuration(data_file: %s)', data_file)
|
|
504
720
|
end
|
|
505
721
|
|
|
506
722
|
##
|
|
@@ -514,13 +730,13 @@ module Kameleoon
|
|
|
514
730
|
end
|
|
515
731
|
|
|
516
732
|
def dispose
|
|
733
|
+
Logging::KameleoonLogger.debug('CALL: KameleoonClient.dispose')
|
|
517
734
|
stop_configuration_update_job_if_needed
|
|
518
735
|
stop_real_time_configuration_service_if_needed
|
|
519
736
|
@visitor_manager.stop
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
print "Kameleoon SDK Log: #{text}\n" if @verbose_mode
|
|
737
|
+
@tracking_manager.stop
|
|
738
|
+
@scheduler.shutdown
|
|
739
|
+
Logging::KameleoonLogger.debug('RETURN: KameleoonClient.dispose')
|
|
524
740
|
end
|
|
525
741
|
|
|
526
742
|
# Uncomment when using storage
|
|
@@ -540,8 +756,12 @@ module Kameleoon
|
|
|
540
756
|
|
|
541
757
|
##
|
|
542
758
|
# helper method for getting variation key for feature flag
|
|
543
|
-
def _get_feature_variation_key(visitor_code, feature_key
|
|
544
|
-
|
|
759
|
+
def _get_feature_variation_key(visitor_code, feature_key)
|
|
760
|
+
Logging::KameleoonLogger.debug(
|
|
761
|
+
"CALL: KameleoonClient._get_feature_variation_key(visitor_code: '%s', feature_key: '%s')",
|
|
762
|
+
visitor_code, feature_key
|
|
763
|
+
)
|
|
764
|
+
feature_flag = @data_manager.data_file.get_feature_flag(feature_key)
|
|
545
765
|
variation, rule = _calculate_variation_key_for_feature(visitor_code, feature_flag)
|
|
546
766
|
variation_key = _get_variation_key(variation, rule, feature_flag)
|
|
547
767
|
visitor = nil
|
|
@@ -554,13 +774,22 @@ module Kameleoon
|
|
|
554
774
|
visitor.assign_variation(as_variation)
|
|
555
775
|
end
|
|
556
776
|
end
|
|
557
|
-
|
|
777
|
+
@tracking_manager.add_visitor_code(visitor_code)
|
|
778
|
+
Logging::KameleoonLogger.debug(
|
|
779
|
+
"RETURN: KameleoonClient._get_feature_variation_key(visitor_code: '%s', feature_key: '%s')" \
|
|
780
|
+
" -> (feature_flag: %s, variation_key: '%s')",
|
|
781
|
+
visitor_code, feature_key, feature_flag, variation_key
|
|
782
|
+
)
|
|
558
783
|
[feature_flag, variation_key]
|
|
559
784
|
end
|
|
560
785
|
|
|
561
786
|
##
|
|
562
787
|
# helper method for calculate variation key for feature flag
|
|
563
788
|
def _calculate_variation_key_for_feature(visitor_code, feature_flag)
|
|
789
|
+
Logging::KameleoonLogger.debug(
|
|
790
|
+
"CALL: KameleoonClient._calculate_variation_key_for_feature(visitor_code: '%s', feature_flag: %s)",
|
|
791
|
+
visitor_code, feature_flag
|
|
792
|
+
)
|
|
564
793
|
# no rules -> return default_variation_key
|
|
565
794
|
feature_flag.rules.each do |rule|
|
|
566
795
|
# check if visitor is targeted for rule, else next rule
|
|
@@ -571,20 +800,41 @@ module Kameleoon
|
|
|
571
800
|
code_for_hash = vis&.mapping_identifier || visitor_code
|
|
572
801
|
# uses for rule exposition
|
|
573
802
|
hash_rule = Utils::HashDouble.obtain_rule(code_for_hash, rule.id, rule.respool_time)
|
|
803
|
+
Logging::KameleoonLogger.debug("Calculated hash_rule: %s for visitor_code: '%s'", hash_rule, code_for_hash)
|
|
574
804
|
# check main expostion for rule with hashRule
|
|
575
805
|
if hash_rule <= rule.exposition
|
|
576
|
-
|
|
806
|
+
if rule.targeted_delivery_type?
|
|
807
|
+
Logging::KameleoonLogger.debug(
|
|
808
|
+
"RETURN: KameleoonClient._calculate_variation_key_for_feature(visitor_code: '%s', feature_flag: %s) " \
|
|
809
|
+
'-> (variation: %s, rule: %s)',
|
|
810
|
+
visitor_code, feature_flag, rule.first_variation, rule
|
|
811
|
+
)
|
|
812
|
+
return [rule.first_variation, rule]
|
|
813
|
+
end
|
|
577
814
|
|
|
578
815
|
# uses for variation's expositions
|
|
579
816
|
hash_variation = Utils::HashDouble.obtain_rule(code_for_hash, rule.experiment_id, rule.respool_time)
|
|
817
|
+
Logging::KameleoonLogger.debug(
|
|
818
|
+
"Calculated hash_variation: %s for visitor_code: '%s'", hash_variation, code_for_hash
|
|
819
|
+
)
|
|
580
820
|
# get variation key with new hashVariation
|
|
581
821
|
variation = rule.get_variation(hash_variation)
|
|
582
|
-
|
|
822
|
+
unless variation.nil?
|
|
823
|
+
Logging::KameleoonLogger.debug(
|
|
824
|
+
"RETURN: KameleoonClient._calculate_variation_key_for_feature(visitor_code: '%s', " \
|
|
825
|
+
'feature_flag: %s) -> (variation: %s, rule: %s)', visitor_code, feature_flag, variation, rule
|
|
826
|
+
)
|
|
827
|
+
return [variation, rule]
|
|
828
|
+
end
|
|
583
829
|
# if visitor is targeted for targeted rule then break cycle -> return default
|
|
584
830
|
elsif rule.targeted_delivery_type?
|
|
585
831
|
break
|
|
586
832
|
end
|
|
587
833
|
end
|
|
834
|
+
Logging::KameleoonLogger.debug(
|
|
835
|
+
"RETURN: KameleoonClient._calculate_variation_key_for_feature(visitor_code: '%s', feature_flag: %s) " \
|
|
836
|
+
'-> (variation: nil, rule: nil)', visitor_code, feature_flag
|
|
837
|
+
)
|
|
588
838
|
[nil, nil]
|
|
589
839
|
end
|
|
590
840
|
|
|
@@ -595,55 +845,6 @@ module Kameleoon
|
|
|
595
845
|
feature_flag.default_variation_key
|
|
596
846
|
end
|
|
597
847
|
|
|
598
|
-
##
|
|
599
|
-
# helper method for sending tracking requests for new FF
|
|
600
|
-
def _send_tracking_request(visitor_code, visitor = nil, force_request = true, is_unique_identifier = false)
|
|
601
|
-
if visitor.nil?
|
|
602
|
-
visitor = @visitor_manager.get_visitor(visitor_code)
|
|
603
|
-
return if visitor.nil? && @data_file.settings.is_consent_required
|
|
604
|
-
end
|
|
605
|
-
use_mapping_value, visitor = create_anonymous_if_required(visitor_code, visitor, is_unique_identifier)
|
|
606
|
-
consent = consent_provided?(visitor)
|
|
607
|
-
user_agent = visitor&.user_agent
|
|
608
|
-
unsent = visitor.nil? ? [] : select_unsent_data(visitor, consent)
|
|
609
|
-
if unsent.empty?
|
|
610
|
-
return unless force_request && consent
|
|
611
|
-
|
|
612
|
-
unsent.push(Network::ActivityEvent.new)
|
|
613
|
-
end
|
|
614
|
-
log "Start post tracking: #{unsent.inspect}"
|
|
615
|
-
@network_manager.send_tracking_data(visitor_code, unsent, user_agent, use_mapping_value)
|
|
616
|
-
end
|
|
617
|
-
|
|
618
|
-
def create_anonymous_if_required(visitor_code, visitor, is_unique_identifier)
|
|
619
|
-
use_mapping_value = is_unique_identifier && !visitor&.mapping_identifier.nil?
|
|
620
|
-
# need to find if anonymous visitor is behind unique (anonym doesn't exist if MappingIdentifier == null)
|
|
621
|
-
if is_unique_identifier && visitor&.mapping_identifier.nil?
|
|
622
|
-
# We haven't anonymous behind, in this case we should create "fake" anonymous with id == visitorCode
|
|
623
|
-
# and link it with with mapping value == visitorCode (like we do as we have real anonymous visitor)
|
|
624
|
-
visitor = @visitor_manager.add_data(visitor_code,
|
|
625
|
-
CustomData.new(@data_file.custom_data_info.mapping_identifier_index,
|
|
626
|
-
visitor_code))
|
|
627
|
-
end
|
|
628
|
-
[use_mapping_value, visitor]
|
|
629
|
-
end
|
|
630
|
-
|
|
631
|
-
def select_unsent_data(visitor, consent)
|
|
632
|
-
unsent = []
|
|
633
|
-
if consent
|
|
634
|
-
visitor.enumerate_sendable_data { |data| unsent.push(data) unless data.sent }
|
|
635
|
-
else
|
|
636
|
-
visitor.conversions.enumerate { |conversion| unsent.push(conversion) unless conversion.sent }
|
|
637
|
-
if @data_file.has_any_targeted_delivery_rule
|
|
638
|
-
visitor.variations.enumerate do |variation|
|
|
639
|
-
unsent.push(variation) unless
|
|
640
|
-
variation.sent || (variation.rule_type != Configuration::RuleType::TARGETED_DELIVERY)
|
|
641
|
-
end
|
|
642
|
-
end
|
|
643
|
-
end
|
|
644
|
-
unsent
|
|
645
|
-
end
|
|
646
|
-
|
|
647
848
|
##
|
|
648
849
|
# helper method for fetching values from a Variable
|
|
649
850
|
def _parse_feature_variable(variable)
|
|
@@ -658,8 +859,9 @@ module Kameleoon
|
|
|
658
859
|
end
|
|
659
860
|
end
|
|
660
861
|
|
|
661
|
-
def
|
|
662
|
-
|
|
862
|
+
def set_unique_identifier(visitor_code, is_unique_identifier)
|
|
863
|
+
Logging::KameleoonLogger.warning("The 'isUniqueIdentifier' parameter is deprecated. Please, add 'UniqueIdentifier' to a visitor instead.")
|
|
864
|
+
@visitor_manager.add_data(visitor_code, UniqueIdentifier.new(is_unique_identifier))
|
|
663
865
|
end
|
|
664
866
|
end
|
|
665
867
|
end
|