vwo-sdk 1.23.1 → 1.25.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/vwo/constants.rb +7 -1
- data/lib/vwo/core/variation_decider.rb +16 -3
- data/lib/vwo/enums.rb +7 -4
- data/lib/vwo/schemas/settings_file.rb +7 -0
- data/lib/vwo/services/event_dispatcher.rb +34 -0
- data/lib/vwo/services/settings_file_manager.rb +3 -1
- data/lib/vwo/utils/custom_dimensions.rb +3 -1
- data/lib/vwo/utils/function.rb +5 -0
- data/lib/vwo/utils/impression.rb +184 -2
- data/lib/vwo/utils/request.rb +14 -0
- data/lib/vwo/utils/utility.rb +6 -0
- data/lib/vwo.rb +92 -90
- 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: 4871df5d5a50f01ed13a11692aa6b114f03242f4c9257eccb48bce2a65beaa7c
|
4
|
+
data.tar.gz: fdd46869b068d589e4a85402d10d8852c4bfc48084e75a18fe8631f3a99b07a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c23fe3a4fbcb4c85ef1af73a7ef9bb37a0a79eb4f628bad726f66394291cd93d24cecc066a662799670d10b703265eb3afe72a689ce060a2756eb84d0bfce69
|
7
|
+
data.tar.gz: f60e3e5a8b96e2ab878929c857d4c8d5c3071e6439e811ac59e7bfa00b488f6c79583ebbfa4a8995a3adac5faf80b7c9293ebea3fa0da231224c684ed39adbb4
|
data/lib/vwo/constants.rb
CHANGED
@@ -27,7 +27,7 @@ class VWO
|
|
27
27
|
HTTP_PROTOCOL = 'http://'
|
28
28
|
HTTPS_PROTOCOL = 'https://'
|
29
29
|
URL_NAMESPACE = '6ba7b811-9dad-11d1-80b4-00c04fd430c8'
|
30
|
-
SDK_VERSION = '1.
|
30
|
+
SDK_VERSION = '1.25.0'
|
31
31
|
SDK_NAME = 'ruby'
|
32
32
|
VWO_DELIMITER = '_vwo_'
|
33
33
|
MAX_EVENTS_PER_REQUEST = 5000
|
@@ -44,6 +44,7 @@ class VWO
|
|
44
44
|
TRACK_GOAL = '/server-side/track-goal'
|
45
45
|
PUSH = '/server-side/push'
|
46
46
|
BATCH_EVENTS = '/server-side/batch-events'
|
47
|
+
EVENTS = '/events/t'
|
47
48
|
end
|
48
49
|
|
49
50
|
module EVENTS
|
@@ -113,5 +114,10 @@ class VWO
|
|
113
114
|
FEATURE_TEST = 'FEATURE_TEST'
|
114
115
|
FEATURE_ROLLOUT = 'FEATURE_ROLLOUT'
|
115
116
|
end
|
117
|
+
|
118
|
+
module EventEnum
|
119
|
+
VWO_VARIATION_SHOWN = 'vwo_variationShown'
|
120
|
+
VWO_SYNC_VISITOR_PROP = 'vwo_syncVisitorProp'
|
121
|
+
end
|
116
122
|
end
|
117
123
|
end
|
@@ -95,6 +95,10 @@ class VWO
|
|
95
95
|
:vwo_user_id => generator_for(user_id, @settings_file['accountId'])
|
96
96
|
}
|
97
97
|
|
98
|
+
if campaign.has_key?("name")
|
99
|
+
decision[:campaign_name] = campaign['name']
|
100
|
+
end
|
101
|
+
|
98
102
|
if is_campaign_part_of_group
|
99
103
|
group_id = @settings_file["campaignGroups"][campaign["id"].to_s]
|
100
104
|
decision[:group_id] = group_id
|
@@ -459,10 +463,19 @@ class VWO
|
|
459
463
|
# @return[Hash]
|
460
464
|
|
461
465
|
def evaluate_whitelisting(user_id, campaign, api_name, campaign_key, variation_targeting_variables = {}, disable_logs = false)
|
462
|
-
if
|
463
|
-
|
466
|
+
if campaign.key?('isUserListEnabled') && campaign["isUserListEnabled"]
|
467
|
+
vwo_user_id = generator_for(user_id, @settings_file['accountId'])
|
468
|
+
if variation_targeting_variables.nil?
|
469
|
+
variation_targeting_variables = { _vwo_user_id: vwo_user_id }
|
470
|
+
else
|
471
|
+
variation_targeting_variables[:_vwo_user_id] = vwo_user_id
|
472
|
+
end
|
464
473
|
else
|
465
|
-
variation_targeting_variables
|
474
|
+
if variation_targeting_variables.nil?
|
475
|
+
variation_targeting_variables = { _vwo_user_id: user_id }
|
476
|
+
else
|
477
|
+
variation_targeting_variables[:_vwo_user_id] = user_id
|
478
|
+
end
|
466
479
|
end
|
467
480
|
targeted_variations = []
|
468
481
|
|
data/lib/vwo/enums.rb
CHANGED
@@ -114,6 +114,9 @@ class VWO
|
|
114
114
|
BEFORE_FLUSHING = '(%<file>s): Flushing events queue %<manually>s having %<length>s events %<timer>s queue summary: %<queue_metadata>s'
|
115
115
|
EVENT_BATCHING_INSUFFICIENT = '(%<file>s): %<key>s not provided, assigning default value'
|
116
116
|
GOT_ELIGIBLE_CAMPAIGNS = "(%<file>s): Campaigns:%<eligible_campaigns_key>s are eligible, %<ineligible_campaigns_log_text>s are ineligible from the Group:%<group_name>s for the User ID:%<user_id>s"
|
117
|
+
IMPRESSION_FOR_EVENT_ARCH_TRACK_USER = "(%<file>s): impression built for vwo_variationShown event for account ID:%<a>s, user ID:%<u>s, and campaign ID:%<c>s"
|
118
|
+
IMPRESSION_FOR_EVENT_ARCH_TRACK_GOAL = "(%<file>s): impression built for %<goal_identifier>s event for account ID:%<a>s, user ID:%<u>s, and campaign ID:%<c>s"
|
119
|
+
IMPRESSION_FOR_EVENT_ARCH_PUSH = "(%<file>s): impression built for visitor property:%<property>s for account ID:%<a>s and user ID:%<u>s"
|
117
120
|
end
|
118
121
|
|
119
122
|
# Info Messages
|
@@ -128,9 +131,10 @@ class VWO
|
|
128
131
|
AUDIENCE_CONDITION_NOT_MET = '(%<file>s): userId:%<user_id>s does not become part of campaign because of not meeting audience conditions'
|
129
132
|
GOT_VARIATION_FOR_USER = '(%<file>s): userId:%<user_id>s for campaign:%<campaign_key>s got variationName:%<variation_name>s'
|
130
133
|
USER_GOT_NO_VARIATION = '(%<file>s): userId:%<user_id>s for campaign:%<campaign_key>s did not allot any variation'
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
+
IMPRESSION_SUCCESS_FOR_EVENT_ARCH = '(%<file>s): Impression for %<event>s - %<url>s was successfully received by VWO for account ID:%<a>s'
|
135
|
+
IMPRESSION_SUCCESS = '(%<file>s): Impression event - %<end_point>s was successfully received by VWO having main keys: accountId:%<account_id>s campaignId:%<campaign_id>s and variationId:%<variation_id>s'
|
136
|
+
MAIN_KEYS_FOR_IMPRESSION = '(%<file>s): Having main keys: accountId:%<account_id>s campaignId:%<campaign_id>s and variationId:%<variation_id>s}'
|
137
|
+
MAIN_KEYS_FOR_PUSH_API = '(%<file>s): Having main keys: accountId:%<account_id>s u:%<u>s and tags:%<tags>s}'
|
134
138
|
INVALID_VARIATION_KEY = '(%<file>s): Variation was not assigned to userId:%<user_id>s for campaign:%<campaign_key>s'
|
135
139
|
|
136
140
|
USER_IN_FEATURE_ROLLOUT = '(%<file>s): User ID:%<user_id>s is in feature rollout:%<campaign_key>s'
|
@@ -201,7 +205,6 @@ class VWO
|
|
201
205
|
TAG_KEY_LENGTH_EXCEEDED = '(%<file>s): In API: %<api_name>s, the length of tag_key:%<tag_key>s and userID: %<user_id>s can not be greater than 255'
|
202
206
|
TRACK_API_MISSING_PARAMS = '(%<file>s): "track" API got bad parameters. It expects campaignKey(null/String/array) as first, userId(String/Number) as second and goalIdentifier (string) as third argument. options is revenueValue(Float/Number/String) and is required for revenue goal only.'
|
203
207
|
NO_CAMPAIGN_FOUND = '(%<file>s): No campaign found for goal_identifier:%<goal_identifier>s. Please verify from VWO app.'
|
204
|
-
INVALID_TRACK_RETURNING_USER_VALUE = '(%<file>s): should_track_returning_user should be boolean'
|
205
208
|
INVALID_GOAL_TYPE = '(%<file>s): goal_type_to_track should be certain strings'
|
206
209
|
EVENT_BATCHING_NOT_OBJECT = '(%<file>s): Batch events settings are not of type object.'
|
207
210
|
EVENTS_PER_REQUEST_INVALID = '(%<file>s): events_per_request should be an integer'
|
@@ -26,6 +26,9 @@ class VWO
|
|
26
26
|
accountId: {
|
27
27
|
type: %w[number string]
|
28
28
|
},
|
29
|
+
isEventArchEnabled: {
|
30
|
+
type: ['boolean']
|
31
|
+
},
|
29
32
|
campaigns: {
|
30
33
|
if: {
|
31
34
|
type: 'array'
|
@@ -73,6 +76,9 @@ class VWO
|
|
73
76
|
key: {
|
74
77
|
type: ['string']
|
75
78
|
},
|
79
|
+
name: {
|
80
|
+
type: ['string']
|
81
|
+
},
|
76
82
|
status: {
|
77
83
|
type: ['string']
|
78
84
|
},
|
@@ -92,6 +98,7 @@ class VWO
|
|
92
98
|
}
|
93
99
|
},
|
94
100
|
isBucketingSeedEnabled: ['boolean'],
|
101
|
+
isUserListEnabled: ['boolean'],
|
95
102
|
minItems: 2
|
96
103
|
}
|
97
104
|
},
|
@@ -15,11 +15,13 @@
|
|
15
15
|
require_relative '../logger'
|
16
16
|
require_relative '../enums'
|
17
17
|
require_relative '../utils/request'
|
18
|
+
require_relative '../constants'
|
18
19
|
|
19
20
|
class VWO
|
20
21
|
module Services
|
21
22
|
class EventDispatcher
|
22
23
|
include VWO::Enums
|
24
|
+
include VWO::CONSTANTS
|
23
25
|
|
24
26
|
EXCLUDE_KEYS = ['url'].freeze
|
25
27
|
|
@@ -63,6 +65,38 @@ class VWO
|
|
63
65
|
)
|
64
66
|
false
|
65
67
|
end
|
68
|
+
|
69
|
+
def dispatch_event_arch_post(params, post_data)
|
70
|
+
return true if @is_development_mode
|
71
|
+
|
72
|
+
url = HTTPS_PROTOCOL + ENDPOINTS::BASE_URL + ENDPOINTS::EVENTS
|
73
|
+
resp = VWO::Utils::Request.event_post(url, params, post_data, SDK_NAME)
|
74
|
+
if resp.code == '200'
|
75
|
+
@logger.log(
|
76
|
+
LogLevelEnum::INFO,
|
77
|
+
format(
|
78
|
+
LogMessageEnum::InfoMessages::IMPRESSION_SUCCESS_FOR_EVENT_ARCH,
|
79
|
+
file: FileNameEnum::EventDispatcher,
|
80
|
+
event: 'visitor property:' + JSON.generate(post_data[:d][:visitor][:props]),
|
81
|
+
url: url,
|
82
|
+
a: params[:a]
|
83
|
+
)
|
84
|
+
)
|
85
|
+
true
|
86
|
+
else
|
87
|
+
@logger.log(
|
88
|
+
LogLevelEnum::ERROR,
|
89
|
+
format(LogMessageEnum::ErrorMessages::IMPRESSION_FAILED, file: FileNameEnum::EventDispatcher, end_point: url)
|
90
|
+
)
|
91
|
+
false
|
92
|
+
end
|
93
|
+
rescue StandardError
|
94
|
+
@logger.log(
|
95
|
+
LogLevelEnum::ERROR,
|
96
|
+
format(LogMessageEnum::ErrorMessages::IMPRESSION_FAILED, file: FileNameEnum::EventDispatcher, end_point: url)
|
97
|
+
)
|
98
|
+
false
|
99
|
+
end
|
66
100
|
end
|
67
101
|
end
|
68
102
|
end
|
@@ -17,6 +17,7 @@ require_relative '../logger'
|
|
17
17
|
require_relative '../enums'
|
18
18
|
require_relative '../constants'
|
19
19
|
require_relative './impression'
|
20
|
+
require_relative './utility'
|
20
21
|
|
21
22
|
# Utility module for helper math and random functions
|
22
23
|
class VWO
|
@@ -25,6 +26,7 @@ class VWO
|
|
25
26
|
include VWO::CONSTANTS
|
26
27
|
include VWO::Enums
|
27
28
|
include VWO::Utils::Impression
|
29
|
+
include VWO::Utils::Utility
|
28
30
|
|
29
31
|
def get_url_params(settings_file, tag_key, tag_value, user_id, sdk_key)
|
30
32
|
url = HTTPS_PROTOCOL + ENDPOINTS::BASE_URL + ENDPOINTS::PUSH
|
@@ -39,7 +41,7 @@ class VWO
|
|
39
41
|
format(
|
40
42
|
LogMessageEnum::DebugMessages::PARAMS_FOR_PUSH_CALL,
|
41
43
|
file: FileNameEnum::CustomDimensionsUtil,
|
42
|
-
properties:
|
44
|
+
properties: remove_sensitive_properties(params)
|
43
45
|
)
|
44
46
|
)
|
45
47
|
params
|
data/lib/vwo/utils/function.rb
CHANGED
data/lib/vwo/utils/impression.rb
CHANGED
@@ -19,6 +19,7 @@ require_relative '../enums'
|
|
19
19
|
require_relative '../constants'
|
20
20
|
require_relative 'function'
|
21
21
|
require_relative 'uuid'
|
22
|
+
require_relative 'utility'
|
22
23
|
|
23
24
|
# Creates the impression from the arguments passed
|
24
25
|
class VWO
|
@@ -28,6 +29,7 @@ class VWO
|
|
28
29
|
include VWO::CONSTANTS
|
29
30
|
include VWO::Utils::Function
|
30
31
|
include UUID
|
32
|
+
include VWO::Utils::Utility
|
31
33
|
|
32
34
|
# Creates the impression from the arguments passed
|
33
35
|
#
|
@@ -76,7 +78,7 @@ class VWO
|
|
76
78
|
format(
|
77
79
|
LogMessageEnum::DebugMessages::IMPRESSION_FOR_TRACK_USER,
|
78
80
|
file: FileNameEnum::ImpressionUtil,
|
79
|
-
properties:
|
81
|
+
properties: remove_sensitive_properties(impression)
|
80
82
|
)
|
81
83
|
)
|
82
84
|
else
|
@@ -88,7 +90,7 @@ class VWO
|
|
88
90
|
format(
|
89
91
|
LogMessageEnum::DebugMessages::IMPRESSION_FOR_TRACK_GOAL,
|
90
92
|
file: FileNameEnum::ImpressionUtil,
|
91
|
-
properties:
|
93
|
+
properties: remove_sensitive_properties(impression)
|
92
94
|
)
|
93
95
|
)
|
94
96
|
end
|
@@ -162,6 +164,186 @@ class VWO
|
|
162
164
|
end
|
163
165
|
impression
|
164
166
|
end
|
167
|
+
|
168
|
+
# Builds generic properties for different tracking calls required by VWO servers.
|
169
|
+
#
|
170
|
+
# @param[Hash] :settings_file
|
171
|
+
# @param[String] :sdk_key
|
172
|
+
# @param[String] :event_name
|
173
|
+
# @param[Hash] :usage_stats
|
174
|
+
# @return[Hash] :properties
|
175
|
+
#
|
176
|
+
def get_events_base_properties(settings_file, event_name, usage_stats = {})
|
177
|
+
properties = {
|
178
|
+
en: event_name,
|
179
|
+
a: settings_file['accountId'],
|
180
|
+
env: settings_file['sdkKey'],
|
181
|
+
eTime: get_current_unix_timestamp_in_millis,
|
182
|
+
random: get_random_number,
|
183
|
+
p: "FS"
|
184
|
+
}
|
185
|
+
|
186
|
+
if event_name == EventEnum::VWO_VARIATION_SHOWN
|
187
|
+
properties = properties.merge(usage_stats)
|
188
|
+
end
|
189
|
+
properties
|
190
|
+
end
|
191
|
+
|
192
|
+
# Builds generic payload required by all the different tracking calls.
|
193
|
+
#
|
194
|
+
# @param[Hash] :settings_file
|
195
|
+
# @param[String] :user_id
|
196
|
+
# @param[String] :event_name
|
197
|
+
# @param[Hash] :usage_stats
|
198
|
+
# @return[Hash] :properties
|
199
|
+
#
|
200
|
+
def get_event_base_payload(settings_file, user_id, event_name, usage_stats = {})
|
201
|
+
uuid = generator_for(user_id, (settings_file['accountId']))
|
202
|
+
sdk_key = settings_file['sdkKey']
|
203
|
+
|
204
|
+
props = {
|
205
|
+
sdkName: SDK_NAME,
|
206
|
+
sdkVersion: SDK_VERSION,
|
207
|
+
'$visitor': {
|
208
|
+
props: {
|
209
|
+
vwo_fs_environment: sdk_key
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
# if usage_stats
|
215
|
+
# props = props.merge(usage_stats)
|
216
|
+
# end
|
217
|
+
|
218
|
+
properties = {
|
219
|
+
d: {
|
220
|
+
msgId: uuid + '_' + Time.now.to_i.to_s,
|
221
|
+
visId: uuid,
|
222
|
+
sessionId: Time.now.to_i,
|
223
|
+
event: {
|
224
|
+
props: props,
|
225
|
+
name: event_name,
|
226
|
+
time: get_current_unix_timestamp_in_millis
|
227
|
+
},
|
228
|
+
visitor: {
|
229
|
+
props: {
|
230
|
+
vwo_fs_environment: sdk_key
|
231
|
+
}
|
232
|
+
}
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
properties
|
237
|
+
end
|
238
|
+
|
239
|
+
# Builds payload to track the visitor.
|
240
|
+
#
|
241
|
+
# @param[Hash] :settings_file
|
242
|
+
# @param[String] :user_id
|
243
|
+
# @param[String] :event_name
|
244
|
+
# @param[Integer] :campaign_id
|
245
|
+
# @param[Integer] :variation_id
|
246
|
+
# @param[Hash] :usage_stats
|
247
|
+
# @return[Hash] :properties
|
248
|
+
#
|
249
|
+
def get_track_user_payload_data(settings_file, user_id, event_name, campaign_id, variation_id, usage_stats = {})
|
250
|
+
properties = get_event_base_payload(settings_file, user_id, event_name)
|
251
|
+
properties[:d][:event][:props][:id] = campaign_id
|
252
|
+
properties[:d][:event][:props][:variation] = variation_id
|
253
|
+
|
254
|
+
#this is currently required by data-layer team, we can make changes on DACDN and remove it from here
|
255
|
+
properties[:d][:event][:props][:isFirst] = 1
|
256
|
+
|
257
|
+
logger = VWO::Logger.get_instance
|
258
|
+
logger.log(
|
259
|
+
LogLevelEnum::DEBUG,
|
260
|
+
format(
|
261
|
+
LogMessageEnum::DebugMessages::IMPRESSION_FOR_EVENT_ARCH_TRACK_USER,
|
262
|
+
file: FileNameEnum::ImpressionUtil,
|
263
|
+
a: settings_file['accountId'],
|
264
|
+
u: user_id,
|
265
|
+
c: campaign_id.to_s
|
266
|
+
)
|
267
|
+
)
|
268
|
+
properties
|
269
|
+
end
|
270
|
+
|
271
|
+
# Builds payload to track the Goal.
|
272
|
+
#
|
273
|
+
# @param[Hash] :settings_file
|
274
|
+
# @param[String] :user_id
|
275
|
+
# @param[String] :event_name
|
276
|
+
# @param[Integer] :revenue_value
|
277
|
+
# @param[Hash] :metric_map
|
278
|
+
# @param[Array] :revenue_props
|
279
|
+
#
|
280
|
+
# @return[Hash] :properties
|
281
|
+
#
|
282
|
+
def get_track_goal_payload_data(settings_file, user_id, event_name, revenue_value, metric_map, revenue_props = [])
|
283
|
+
properties = get_event_base_payload(settings_file, user_id, event_name)
|
284
|
+
|
285
|
+
logger = VWO::Logger.get_instance
|
286
|
+
metric = {}
|
287
|
+
metric_map.each do |campaign_id, goal_id|
|
288
|
+
metric[('id_' + campaign_id.to_s).to_sym] = ['g_' + goal_id.to_s]
|
289
|
+
logger.log(
|
290
|
+
LogLevelEnum::DEBUG,
|
291
|
+
format(
|
292
|
+
LogMessageEnum::DebugMessages::IMPRESSION_FOR_EVENT_ARCH_TRACK_GOAL,
|
293
|
+
file: FileNameEnum::ImpressionUtil,
|
294
|
+
goal_identifier: event_name,
|
295
|
+
a: settings_file['accountId'],
|
296
|
+
u: user_id,
|
297
|
+
c: campaign_id
|
298
|
+
)
|
299
|
+
)
|
300
|
+
end
|
301
|
+
|
302
|
+
properties[:d][:event][:props][:vwoMeta] = {
|
303
|
+
metric: metric
|
304
|
+
}
|
305
|
+
|
306
|
+
if revenue_props.length() != 0 && revenue_value
|
307
|
+
revenue_props.each do |revenue_prop|
|
308
|
+
properties[:d][:event][:props][:vwoMeta][revenue_prop.to_sym] = revenue_value
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
properties[:d][:event][:props][:isCustomEvent] = true
|
313
|
+
properties
|
314
|
+
end
|
315
|
+
|
316
|
+
# Builds payload to appply post segmentation on VWO campaign reports.
|
317
|
+
#
|
318
|
+
# @param[Hash] :settings_file
|
319
|
+
# @param[String] :user_id
|
320
|
+
# @param[String] :event_name
|
321
|
+
# @param[Hash] :custom_dimension_map
|
322
|
+
#
|
323
|
+
# @return[Hash] :properties
|
324
|
+
#
|
325
|
+
def get_push_payload_data(settings_file, user_id, event_name, custom_dimension_map = {})
|
326
|
+
properties = get_event_base_payload(settings_file, user_id, event_name)
|
327
|
+
properties[:d][:event][:props][:isCustomEvent] = true
|
328
|
+
|
329
|
+
custom_dimension_map.each do |tag_key, tag_value|
|
330
|
+
properties[:d][:event][:props][('$visitor'.to_sym)][:props][tag_key] = tag_value
|
331
|
+
properties[:d][:visitor][:props][tag_key] = tag_value
|
332
|
+
end
|
333
|
+
|
334
|
+
logger = VWO::Logger.get_instance
|
335
|
+
logger.log(
|
336
|
+
LogLevelEnum::DEBUG,
|
337
|
+
format(
|
338
|
+
LogMessageEnum::DebugMessages::IMPRESSION_FOR_EVENT_ARCH_PUSH,
|
339
|
+
file: FileNameEnum::ImpressionUtil,
|
340
|
+
a: settings_file['accountId'],
|
341
|
+
u: user_id,
|
342
|
+
property: JSON.generate(custom_dimension_map)
|
343
|
+
)
|
344
|
+
)
|
345
|
+
properties
|
346
|
+
end
|
165
347
|
end
|
166
348
|
end
|
167
349
|
end
|
data/lib/vwo/utils/request.rb
CHANGED
@@ -38,6 +38,20 @@ class VWO
|
|
38
38
|
response = http.post(uri, post_data.to_json, headers)
|
39
39
|
response
|
40
40
|
end
|
41
|
+
|
42
|
+
def self.event_post(url, params, post_data, user_agent_value)
|
43
|
+
uri = URI.parse(url)
|
44
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
45
|
+
http.use_ssl = true
|
46
|
+
uri.query = URI.encode_www_form(params)
|
47
|
+
headers = {
|
48
|
+
'User-Agent' => user_agent_value,
|
49
|
+
'Content-Type' =>'application/json',
|
50
|
+
'Accept'=>'application/json'
|
51
|
+
}
|
52
|
+
response = http.post(uri, post_data.to_json, headers)
|
53
|
+
response
|
54
|
+
end
|
41
55
|
end
|
42
56
|
end
|
43
57
|
end
|
data/lib/vwo/utils/utility.rb
CHANGED
data/lib/vwo.rb
CHANGED
@@ -89,25 +89,6 @@ class VWO
|
|
89
89
|
return
|
90
90
|
end
|
91
91
|
|
92
|
-
if options.key?(:should_track_returning_user)
|
93
|
-
if [true, false].include? options[:should_track_returning_user]
|
94
|
-
@should_track_returning_user = options[:should_track_returning_user]
|
95
|
-
usage_stats[:tr] = 1 if @should_track_returning_user
|
96
|
-
else
|
97
|
-
@logger.log(
|
98
|
-
LogLevelEnum::ERROR,
|
99
|
-
format(
|
100
|
-
LogMessageEnum::ErrorMessages::INVALID_TRACK_RETURNING_USER_VALUE,
|
101
|
-
file: FILE
|
102
|
-
)
|
103
|
-
)
|
104
|
-
@is_instance_valid = false
|
105
|
-
return
|
106
|
-
end
|
107
|
-
else
|
108
|
-
@should_track_returning_user = false
|
109
|
-
end
|
110
|
-
|
111
92
|
if options.key?(:goal_type_to_track)
|
112
93
|
if GOAL_TYPES.key? options[:goal_type_to_track]
|
113
94
|
@goal_type_to_track = options[:goal_type_to_track]
|
@@ -303,10 +284,9 @@ class VWO
|
|
303
284
|
custom_variables = options[:custom_variables]
|
304
285
|
variation_targeting_variables = options[:variation_targeting_variables]
|
305
286
|
|
306
|
-
should_track_returning_user = get_should_track_returning_user(options)
|
307
287
|
# Validate input parameters
|
308
288
|
unless valid_string?(campaign_key) && valid_string?(user_id) && (custom_variables.nil? || valid_hash?(custom_variables)) &&
|
309
|
-
(variation_targeting_variables.nil? || valid_hash?(variation_targeting_variables))
|
289
|
+
(variation_targeting_variables.nil? || valid_hash?(variation_targeting_variables))
|
310
290
|
@logger.log(
|
311
291
|
LogLevelEnum::ERROR,
|
312
292
|
format(
|
@@ -381,7 +361,7 @@ class VWO
|
|
381
361
|
return
|
382
362
|
end
|
383
363
|
|
384
|
-
if is_eligible_to_send_impression(
|
364
|
+
if is_eligible_to_send_impression()
|
385
365
|
if defined?(@batch_events)
|
386
366
|
impression = create_bulk_event_impression(
|
387
367
|
@settings_file,
|
@@ -390,6 +370,10 @@ class VWO
|
|
390
370
|
user_id
|
391
371
|
)
|
392
372
|
@batch_events_queue.enqueue(impression)
|
373
|
+
elsif is_event_arch_enabled
|
374
|
+
properties = get_events_base_properties(@settings_file, EventEnum::VWO_VARIATION_SHOWN, @usage_stats.usage_stats)
|
375
|
+
payload = get_track_user_payload_data(@settings_file, user_id, EventEnum::VWO_VARIATION_SHOWN, campaign['id'], variation['id'])
|
376
|
+
@event_dispatcher.dispatch_event_arch_post(properties, payload)
|
393
377
|
else
|
394
378
|
# Variation found, dispatch it to server
|
395
379
|
impression = create_impression(
|
@@ -408,7 +392,6 @@ class VWO
|
|
408
392
|
format(
|
409
393
|
LogMessageEnum::InfoMessages::IMPRESSION_SUCCESS,
|
410
394
|
file: FILE,
|
411
|
-
sdk_key: @sdk_key,
|
412
395
|
account_id: @account_id,
|
413
396
|
campaign_id: campaign['id'],
|
414
397
|
variation_id: variation['id'],
|
@@ -588,12 +571,11 @@ class VWO
|
|
588
571
|
revenue_value = options[:revenue_value]
|
589
572
|
custom_variables = options[:custom_variables]
|
590
573
|
variation_targeting_variables = options[:variation_targeting_variables]
|
591
|
-
should_track_returning_user = get_should_track_returning_user(options)
|
592
574
|
goal_type_to_track = get_goal_type_to_track(options)
|
593
575
|
|
594
576
|
# Check for valid args
|
595
577
|
unless (valid_string?(campaign_key) || campaign_key.is_a?(Array) || campaign_key.nil?) && valid_string?(user_id) && valid_string?(goal_identifier) && (custom_variables.nil? || valid_hash?(custom_variables)) &&
|
596
|
-
(variation_targeting_variables.nil? || valid_hash?(variation_targeting_variables)) &&
|
578
|
+
(variation_targeting_variables.nil? || valid_hash?(variation_targeting_variables)) && (GOAL_TYPES.key? (goal_type_to_track))
|
597
579
|
# log invalid params
|
598
580
|
@logger.log(
|
599
581
|
LogLevelEnum::ERROR,
|
@@ -614,6 +596,8 @@ class VWO
|
|
614
596
|
return nil
|
615
597
|
end
|
616
598
|
|
599
|
+
metric_map = {}
|
600
|
+
revenue_props = []
|
617
601
|
result = {}
|
618
602
|
campaigns.each do |campaign|
|
619
603
|
begin
|
@@ -683,7 +667,7 @@ class VWO
|
|
683
667
|
updated_goal_identifier += VWO_DELIMITER + goal_identifier
|
684
668
|
@variation_decider.save_user_storage(user_id, campaign['key'], campaign['name'], variation['name'], updated_goal_identifier) if variation['name']
|
685
669
|
# set variation at user storage
|
686
|
-
|
670
|
+
else
|
687
671
|
@logger.log(
|
688
672
|
LogLevelEnum::INFO,
|
689
673
|
format(
|
@@ -709,6 +693,11 @@ class VWO
|
|
709
693
|
revenue_value
|
710
694
|
)
|
711
695
|
@batch_events_queue.enqueue(impression)
|
696
|
+
elsif is_event_arch_enabled
|
697
|
+
metric_map[campaign['id']] = goal['id']
|
698
|
+
if goal['type'] == GoalTypes::REVENUE && !(revenue_props.include? goal['revenueProp'])
|
699
|
+
revenue_props << goal['revenueProp']
|
700
|
+
end
|
712
701
|
else
|
713
702
|
impression = create_impression(
|
714
703
|
@settings_file,
|
@@ -725,7 +714,6 @@ class VWO
|
|
725
714
|
format(
|
726
715
|
LogMessageEnum::InfoMessages::IMPRESSION_SUCCESS,
|
727
716
|
file: FILE,
|
728
|
-
sdk_key: @sdk_key,
|
729
717
|
account_id: @account_id,
|
730
718
|
campaign_id: campaign['id'],
|
731
719
|
variation_id: variation['id'],
|
@@ -737,7 +725,6 @@ class VWO
|
|
737
725
|
format(
|
738
726
|
LogMessageEnum::InfoMessages::MAIN_KEYS_FOR_IMPRESSION,
|
739
727
|
file: FILE,
|
740
|
-
sdk_key: @sdk_key,
|
741
728
|
campaign_id: impression[:experiment_id],
|
742
729
|
account_id: impression[:account_id],
|
743
730
|
variation_id: impression[:combination]
|
@@ -761,6 +748,12 @@ class VWO
|
|
761
748
|
end
|
762
749
|
end
|
763
750
|
|
751
|
+
if is_event_arch_enabled
|
752
|
+
properties = get_events_base_properties(@settings_file, goal_identifier)
|
753
|
+
payload = get_track_goal_payload_data(@settings_file, user_id, goal_identifier, revenue_value, metric_map, revenue_props)
|
754
|
+
@event_dispatcher.dispatch_event_arch_post(properties, payload)
|
755
|
+
end
|
756
|
+
|
764
757
|
if result.length() == 0
|
765
758
|
return nil
|
766
759
|
end
|
@@ -809,7 +802,6 @@ class VWO
|
|
809
802
|
# Retrieve custom variables
|
810
803
|
custom_variables = options[:custom_variables]
|
811
804
|
variation_targeting_variables = options[:variation_targeting_variables]
|
812
|
-
should_track_returning_user = get_should_track_returning_user(options)
|
813
805
|
@logger.log(
|
814
806
|
LogLevelEnum::INFO,
|
815
807
|
format(
|
@@ -821,7 +813,7 @@ class VWO
|
|
821
813
|
)
|
822
814
|
# Validate input parameters
|
823
815
|
unless valid_string?(campaign_key) && valid_string?(user_id) && (custom_variables.nil? || valid_hash?(custom_variables)) &&
|
824
|
-
(variation_targeting_variables.nil? || valid_hash?(variation_targeting_variables))
|
816
|
+
(variation_targeting_variables.nil? || valid_hash?(variation_targeting_variables))
|
825
817
|
@logger.log(
|
826
818
|
LogLevelEnum::ERROR,
|
827
819
|
format(
|
@@ -877,7 +869,7 @@ class VWO
|
|
877
869
|
|
878
870
|
# if campaign type is feature_test Send track call to server
|
879
871
|
|
880
|
-
if is_eligible_to_send_impression(
|
872
|
+
if is_eligible_to_send_impression()
|
881
873
|
if defined?(@batch_events)
|
882
874
|
impression = create_bulk_event_impression(
|
883
875
|
@settings_file,
|
@@ -886,6 +878,10 @@ class VWO
|
|
886
878
|
user_id
|
887
879
|
)
|
888
880
|
@batch_events_queue.enqueue(impression)
|
881
|
+
elsif is_event_arch_enabled
|
882
|
+
properties = get_events_base_properties(@settings_file, EventEnum::VWO_VARIATION_SHOWN, @usage_stats.usage_stats)
|
883
|
+
payload = get_track_user_payload_data(@settings_file, user_id, EventEnum::VWO_VARIATION_SHOWN, campaign['id'], variation['id'])
|
884
|
+
@event_dispatcher.dispatch_event_arch_post(properties, payload)
|
889
885
|
else
|
890
886
|
impression = create_impression(
|
891
887
|
@settings_file,
|
@@ -905,7 +901,6 @@ class VWO
|
|
905
901
|
LogMessageEnum::InfoMessages::MAIN_KEYS_FOR_IMPRESSION,
|
906
902
|
file: FILE,
|
907
903
|
campaign_id: impression[:experiment_id],
|
908
|
-
sdk_key: @sdk_key,
|
909
904
|
account_id: impression[:account_id],
|
910
905
|
variation_id: impression[:combination]
|
911
906
|
)
|
@@ -1136,12 +1131,12 @@ class VWO
|
|
1136
1131
|
# This API method: Makes a call to our server to store the tag_values
|
1137
1132
|
# 1. Validates the arguments being passed
|
1138
1133
|
# 2. Send a call to our server
|
1139
|
-
# @param[String]
|
1140
|
-
# @param[String] :tag_value Value of the tag
|
1134
|
+
# @param[String|Hash] :tag_key key name of the tag OR tagKey/tagValue pair(custom dimension map)
|
1135
|
+
# @param[String] :tag_value Value of the tag OR userId if TagKey is hash
|
1141
1136
|
# @param[String] :user_id ID of the user for which value should be stored
|
1142
1137
|
# @return true if call is made successfully, else false
|
1143
1138
|
|
1144
|
-
def push(tag_key, tag_value, user_id)
|
1139
|
+
def push(tag_key, tag_value, user_id = nil)
|
1145
1140
|
unless @is_instance_valid
|
1146
1141
|
@logger.log(
|
1147
1142
|
LogLevelEnum::ERROR,
|
@@ -1154,7 +1149,16 @@ class VWO
|
|
1154
1149
|
return
|
1155
1150
|
end
|
1156
1151
|
|
1157
|
-
|
1152
|
+
# Argument reshuffling.
|
1153
|
+
custom_dimension_map = {}
|
1154
|
+
if user_id.nil? || tag_key.is_a?(Hash)
|
1155
|
+
custom_dimension_map = convert_to_symbol_hash(tag_key)
|
1156
|
+
user_id = tag_value
|
1157
|
+
else
|
1158
|
+
custom_dimension_map[tag_key.to_sym] = tag_value
|
1159
|
+
end
|
1160
|
+
|
1161
|
+
unless (valid_string?(tag_key) || valid_hash?(tag_key)) && valid_string?(tag_value) && valid_string?(user_id)
|
1158
1162
|
@logger.log(
|
1159
1163
|
LogLevelEnum::ERROR,
|
1160
1164
|
format(
|
@@ -1166,52 +1170,61 @@ class VWO
|
|
1166
1170
|
return false
|
1167
1171
|
end
|
1168
1172
|
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1173
|
+
custom_dimension_map.each do |tag_key, tag_value|
|
1174
|
+
if tag_key.length > PushApi::TAG_KEY_LENGTH
|
1175
|
+
@logger.log(
|
1176
|
+
LogLevelEnum::ERROR,
|
1177
|
+
format(
|
1178
|
+
LogMessageEnum::ErrorMessages::TAG_KEY_LENGTH_EXCEEDED,
|
1179
|
+
file: FILE,
|
1180
|
+
user_id: user_id,
|
1181
|
+
tag_key: tag_key,
|
1182
|
+
api_name: ApiMethods::PUSH
|
1183
|
+
)
|
1178
1184
|
)
|
1179
|
-
|
1180
|
-
|
1181
|
-
end
|
1185
|
+
return false
|
1186
|
+
end
|
1182
1187
|
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1188
|
+
if tag_value.length > PushApi::TAG_VALUE_LENGTH
|
1189
|
+
@logger.log(
|
1190
|
+
LogLevelEnum::ERROR,
|
1191
|
+
format(
|
1192
|
+
LogMessageEnum::ErrorMessages::TAG_VALUE_LENGTH_EXCEEDED,
|
1193
|
+
file: FILE,
|
1194
|
+
user_id: user_id,
|
1195
|
+
tag_value: tag_value,
|
1196
|
+
api_name: ApiMethods::PUSH
|
1197
|
+
)
|
1192
1198
|
)
|
1193
|
-
|
1194
|
-
|
1199
|
+
return false
|
1200
|
+
end
|
1195
1201
|
end
|
1196
1202
|
|
1197
1203
|
if defined?(@batch_events)
|
1198
|
-
|
1199
|
-
|
1204
|
+
custom_dimension_map.each do |tag_key, tag_value|
|
1205
|
+
impression = get_batch_event_url_params(@settings_file, tag_key, tag_value, user_id)
|
1206
|
+
@batch_events_queue.enqueue(impression)
|
1207
|
+
end
|
1208
|
+
elsif is_event_arch_enabled
|
1209
|
+
properties = get_events_base_properties(@settings_file, EventEnum::VWO_SYNC_VISITOR_PROP)
|
1210
|
+
payload = get_push_payload_data(@settings_file, user_id, EventEnum::VWO_SYNC_VISITOR_PROP, custom_dimension_map)
|
1211
|
+
@event_dispatcher.dispatch_event_arch_post(properties, payload)
|
1200
1212
|
else
|
1201
|
-
|
1202
|
-
|
1213
|
+
custom_dimension_map.each do |tag_key, tag_value|
|
1214
|
+
impression = get_url_params(@settings_file, tag_key, tag_value, user_id, @sdk_key)
|
1215
|
+
@event_dispatcher.dispatch(impression)
|
1203
1216
|
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1217
|
+
@logger.log(
|
1218
|
+
LogLevelEnum::INFO,
|
1219
|
+
format(
|
1220
|
+
LogMessageEnum::InfoMessages::MAIN_KEYS_FOR_PUSH_API,
|
1221
|
+
file: FILE,
|
1222
|
+
u: impression['u'],
|
1223
|
+
account_id: impression['account_id'],
|
1224
|
+
tags: impression['tags']
|
1225
|
+
)
|
1213
1226
|
)
|
1214
|
-
|
1227
|
+
end
|
1215
1228
|
end
|
1216
1229
|
true
|
1217
1230
|
rescue StandardError => e
|
@@ -1227,23 +1240,8 @@ class VWO
|
|
1227
1240
|
false
|
1228
1241
|
end
|
1229
1242
|
|
1230
|
-
def
|
1231
|
-
|
1232
|
-
options[:should_track_returning_user] = @should_track_returning_user
|
1233
|
-
elsif ![true, false].include?(options[:should_track_returning_user])
|
1234
|
-
@logger.log(
|
1235
|
-
LogLevelEnum::ERROR,
|
1236
|
-
format(
|
1237
|
-
LogMessageEnum::ErrorMessages::INVALID_TRACK_RETURNING_USER_VALUE,
|
1238
|
-
file: FILE
|
1239
|
-
)
|
1240
|
-
)
|
1241
|
-
end
|
1242
|
-
options[:should_track_returning_user]
|
1243
|
-
end
|
1244
|
-
|
1245
|
-
def is_eligible_to_send_impression(should_track_returning_user = false)
|
1246
|
-
!@user_storage || !@variation_decider.has_stored_variation || should_track_returning_user
|
1243
|
+
def is_eligible_to_send_impression()
|
1244
|
+
!@user_storage || !@variation_decider.has_stored_variation
|
1247
1245
|
end
|
1248
1246
|
|
1249
1247
|
def flush_events
|
@@ -1295,4 +1293,8 @@ class VWO
|
|
1295
1293
|
end
|
1296
1294
|
goal_type_to_track
|
1297
1295
|
end
|
1296
|
+
|
1297
|
+
def is_event_arch_enabled
|
1298
|
+
return @settings_file.key?('isEventArchEnabled') && @settings_file['isEventArchEnabled']
|
1299
|
+
end
|
1298
1300
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vwo-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VWO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codecov
|