vwo-fme-ruby-sdk 1.4.0 → 1.5.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/constants.rb +1 -1
- data/lib/vwo/enums/event_enum.rb +3 -2
- data/lib/vwo/models/schemas/settings_schema_validation.rb +1 -0
- data/lib/vwo/models/settings/settings_model.rb +6 -1
- data/lib/vwo/utils/event_util.rb +13 -0
- data/lib/vwo/utils/network_util.rb +86 -59
- data/lib/vwo/utils/url_util.rb +7 -0
- data/lib/vwo/utils/usage_stats_util.rb +3 -1
- data/lib/vwo.rb +8 -0
- 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: 070ef4b08bf92bddf7d91a7a520a570651ed5c79c2d792a73021889803589f46
|
4
|
+
data.tar.gz: 5a6bb42880b3d4e73da654d33c78e05566bd487c15205918bef6020447793454
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f48860c62dd6c81743ee2647fe7144ba503bff54fc68f4ddb8619bde4ff698b13ba46db401f1ea40abffd30b4909b8ca0a42af628b9b2b71670eef15f54b215
|
7
|
+
data.tar.gz: dd3eaf38a66d744dd3e9f0b553e707610ae1b130980b1359eca5b9ae9ee70f063cfe4dd3a1c43a397676d52a2289e3770638ab1b076cdfc769b5bc72f5bb3f63
|
data/lib/vwo/enums/event_enum.rb
CHANGED
@@ -15,6 +15,7 @@
|
|
15
15
|
# Event types
|
16
16
|
module EventEnum
|
17
17
|
VWO_VARIATION_SHOWN = 'vwo_variationShown'
|
18
|
-
VWO_SYNC_VISITOR_PROP = 'vwo_syncVisitorProp'
|
18
|
+
VWO_SYNC_VISITOR_PROP = 'vwo_syncVisitorProp'
|
19
19
|
VWO_INIT_CALLED = 'vwo_fmeSdkInit'
|
20
|
-
|
20
|
+
VWO_USAGE_STATS = 'vwo_sdkUsageStats'
|
21
|
+
end
|
@@ -84,6 +84,7 @@ class SettingsSchema
|
|
84
84
|
optional(:sdkKey).maybe(:string)
|
85
85
|
required(:version).filled(:integer)
|
86
86
|
required(:accountId).filled(:integer)
|
87
|
+
optional(:usageStatsAccountId).maybe(:integer)
|
87
88
|
optional(:features).array(:hash)
|
88
89
|
required(:campaigns).array(:hash)
|
89
90
|
optional(:groups).maybe(:hash)
|
@@ -17,12 +17,13 @@ require_relative '../campaign/feature_model'
|
|
17
17
|
require_relative '../../constants/constants'
|
18
18
|
|
19
19
|
class SettingsModel
|
20
|
-
attr_reader :sdk_key, :account_id, :version, :collection_prefix,
|
20
|
+
attr_reader :sdk_key, :account_id, :usage_stats_account_id, :version, :collection_prefix,
|
21
21
|
:features, :campaigns, :campaign_groups, :groups, :poll_interval
|
22
22
|
|
23
23
|
def initialize(settings)
|
24
24
|
@sdk_key = settings["sdkKey"]
|
25
25
|
@account_id = settings["accountId"]
|
26
|
+
@usage_stats_account_id = settings["usageStatsAccountId"]
|
26
27
|
@version = settings["version"]
|
27
28
|
@collection_prefix = settings["collectionPrefix"]
|
28
29
|
@poll_interval = settings["pollInterval"] || Constants::POLLING_INTERVAL
|
@@ -59,6 +60,10 @@ class SettingsModel
|
|
59
60
|
@account_id
|
60
61
|
end
|
61
62
|
|
63
|
+
def get_usage_stats_account_id
|
64
|
+
@usage_stats_account_id
|
65
|
+
end
|
66
|
+
|
62
67
|
def get_version
|
63
68
|
@version
|
64
69
|
end
|
data/lib/vwo/utils/event_util.rb
CHANGED
@@ -33,4 +33,17 @@ def send_sdk_init_event(settings_fetch_time, sdk_init_time)
|
|
33
33
|
# Send the constructed payload via POST request
|
34
34
|
NetworkUtil.send_event(properties, payload)
|
35
35
|
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Sends a usage stats event to VWO.
|
39
|
+
# @param usage_stats_account_id - The account id for usage stats.
|
40
|
+
def send_sdk_usage_stats_event(usage_stats_account_id)
|
41
|
+
# create query parameters
|
42
|
+
properties = NetworkUtil.get_events_base_properties(EventEnum::VWO_USAGE_STATS, nil, nil, true, usage_stats_account_id)
|
43
|
+
|
44
|
+
# create payload
|
45
|
+
payload = NetworkUtil.get_sdk_usage_stats_payload_data(EventEnum::VWO_USAGE_STATS, usage_stats_account_id)
|
46
|
+
|
47
|
+
# send event
|
48
|
+
NetworkUtil.send_event(properties, payload)
|
36
49
|
end
|
@@ -32,7 +32,7 @@ class NetworkUtil
|
|
32
32
|
# @return [String] URL-encoded query string
|
33
33
|
def convert_params_to_string(params)
|
34
34
|
return '' if params.nil? || params.empty?
|
35
|
-
|
35
|
+
|
36
36
|
'?' + params.map do |key, value|
|
37
37
|
"#{URI.encode_www_form_component(key.to_s)}=#{URI.encode_www_form_component(value.to_s)}"
|
38
38
|
end.join('&')
|
@@ -80,47 +80,69 @@ class NetworkUtil
|
|
80
80
|
end
|
81
81
|
|
82
82
|
# Builds generic properties for different tracking calls
|
83
|
-
def get_events_base_properties(event_name, visitor_user_agent = '', ip_address = '')
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
visitor_ip: ip_address || '',
|
94
|
-
url: "#{UrlUtil.get_base_url}#{UrlEnum::EVENTS}"
|
83
|
+
def get_events_base_properties(event_name, visitor_user_agent = '', ip_address = '', is_usage_stats_event = false, usage_stat_account_id = '')
|
84
|
+
properties = {
|
85
|
+
en: event_name,
|
86
|
+
a: SettingsService.instance.account_id,
|
87
|
+
eTime: get_current_unix_timestamp_in_millis,
|
88
|
+
random: get_random_number,
|
89
|
+
p: 'FS',
|
90
|
+
visitor_ua: visitor_user_agent || '',
|
91
|
+
visitor_ip: ip_address || '',
|
92
|
+
url: "#{UrlUtil.get_base_url}#{UrlEnum::EVENTS}"
|
95
93
|
}
|
94
|
+
|
95
|
+
if !is_usage_stats_event
|
96
|
+
# set env key for standard sdk events
|
97
|
+
properties[:env] = SettingsService.instance.sdk_key
|
98
|
+
else
|
99
|
+
# set env key for usage stats events
|
100
|
+
properties[:a] = usage_stat_account_id
|
101
|
+
end
|
102
|
+
|
103
|
+
properties
|
96
104
|
end
|
97
105
|
|
98
106
|
# Builds base payload for tracking events
|
99
|
-
def _get_event_base_payload(user_id, event_name, visitor_user_agent = '', ip_address = '')
|
100
|
-
|
107
|
+
def _get_event_base_payload(user_id, event_name, visitor_user_agent = '', ip_address = '', is_usage_stats_event = false, usage_stat_account_id = '')
|
108
|
+
account_id = SettingsService.instance.account_id
|
109
|
+
|
110
|
+
if is_usage_stats_event
|
111
|
+
account_id = usage_stat_account_id
|
112
|
+
end
|
113
|
+
|
114
|
+
uuid = UUIDUtil.get_uuid(user_id.to_s, account_id.to_s)
|
101
115
|
sdk_key = SettingsService.instance.sdk_key
|
102
116
|
|
103
|
-
{
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
},
|
117
|
-
visitor: {
|
118
|
-
props: {
|
119
|
-
vwo_fs_environment: sdk_key
|
120
|
-
}
|
117
|
+
payload = {
|
118
|
+
d: {
|
119
|
+
msgId: "#{uuid}-#{get_current_unix_timestamp_in_millis}",
|
120
|
+
visId: uuid,
|
121
|
+
sessionId: get_current_unix_timestamp,
|
122
|
+
event: {
|
123
|
+
props: {
|
124
|
+
vwo_sdkName: Constants::SDK_NAME,
|
125
|
+
vwo_sdkVersion: Constants::SDK_VERSION,
|
126
|
+
},
|
127
|
+
name: event_name,
|
128
|
+
time: get_current_unix_timestamp_in_millis
|
129
|
+
}
|
121
130
|
}
|
122
131
|
}
|
123
|
-
|
132
|
+
|
133
|
+
if !is_usage_stats_event
|
134
|
+
# set env key for standard sdk events
|
135
|
+
payload[:d][:event][:props][:vwo_envKey] = sdk_key
|
136
|
+
|
137
|
+
# set visitor props for standard sdk events
|
138
|
+
payload[:d][:visitor] = {
|
139
|
+
props: {
|
140
|
+
vwo_fs_environment: sdk_key
|
141
|
+
}
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
payload
|
124
146
|
end
|
125
147
|
|
126
148
|
# Builds track-user payload data
|
@@ -134,18 +156,12 @@ class NetworkUtil
|
|
134
156
|
properties[:d][:visitor_ua] = visitor_user_agent if visitor_user_agent && !visitor_user_agent.empty?
|
135
157
|
properties[:d][:visitor_ip] = ip_address if ip_address && !ip_address.empty?
|
136
158
|
|
137
|
-
# check if usage stats size is greater than 0
|
138
|
-
usage_stats = UsageStatsUtil.get_usage_stats
|
139
|
-
if usage_stats.size > 0
|
140
|
-
properties[:d][:event][:props][:vwoMeta] = usage_stats
|
141
|
-
end
|
142
|
-
|
143
159
|
LoggerService.log(LogLevelEnum::DEBUG, "IMPRESSION_FOR_TRACK_USER", {
|
144
160
|
accountId: SettingsService.instance.account_id,
|
145
161
|
userId: user_id,
|
146
162
|
campaignId: campaign_id
|
147
163
|
})
|
148
|
-
|
164
|
+
|
149
165
|
properties
|
150
166
|
end
|
151
167
|
|
@@ -158,17 +174,17 @@ class NetworkUtil
|
|
158
174
|
properties[:d][:event][:props][:variation] = 1
|
159
175
|
properties[:d][:event][:props][:id] = 1 # Temporary value for ID
|
160
176
|
end
|
161
|
-
|
177
|
+
|
162
178
|
if event_properties.is_a?(Hash) && !event_properties.empty?
|
163
179
|
event_properties.each { |key, value| properties[:d][:event][:props][key] = value }
|
164
180
|
end
|
165
|
-
|
181
|
+
|
166
182
|
LoggerService.log(LogLevelEnum::DEBUG, "IMPRESSION_FOR_TRACK_GOAL", {
|
167
183
|
eventName: event_name,
|
168
184
|
accountId: SettingsService.instance.account_id,
|
169
185
|
userId: user_id
|
170
186
|
})
|
171
|
-
|
187
|
+
|
172
188
|
properties
|
173
189
|
end
|
174
190
|
|
@@ -194,7 +210,7 @@ class NetworkUtil
|
|
194
210
|
# @param sdk_init_time - Time taken to initialize the SDK in milliseconds.
|
195
211
|
# @returns The constructed payload with required fields.
|
196
212
|
def get_sdk_init_event_payload(event_name, settings_fetch_time, sdk_init_time)
|
197
|
-
user_id = SettingsService.instance.account_id + "_" + SettingsService.instance.sdk_key
|
213
|
+
user_id = SettingsService.instance.account_id.to_s + "_" + SettingsService.instance.sdk_key
|
198
214
|
properties = _get_event_base_payload(user_id, event_name, nil, nil)
|
199
215
|
properties[:d][:event][:props][:vwo_fs_environment] = SettingsService.instance.sdk_key
|
200
216
|
properties[:d][:event][:props][:product] = Constants::PRODUCT_NAME
|
@@ -207,6 +223,18 @@ class NetworkUtil
|
|
207
223
|
properties
|
208
224
|
end
|
209
225
|
|
226
|
+
# Constructs the payload for usage stats called event.
|
227
|
+
# @param event_name - The name of the event.
|
228
|
+
# @param usage_stats_account_id - The account id for usage stats.
|
229
|
+
# @returns The constructed payload with required fields.
|
230
|
+
def get_sdk_usage_stats_payload_data(event_name, usage_stats_account_id)
|
231
|
+
user_id = SettingsService.instance.account_id.to_s + "_" + SettingsService.instance.sdk_key
|
232
|
+
properties = _get_event_base_payload(user_id, event_name, nil, nil, true, usage_stats_account_id)
|
233
|
+
properties[:d][:event][:props][:product] = Constants::PRODUCT_NAME
|
234
|
+
properties[:d][:event][:props][:vwoMeta] = UsageStatsUtil.get_usage_stats
|
235
|
+
properties
|
236
|
+
end
|
237
|
+
|
210
238
|
# Sends a POST API request with given properties and payload
|
211
239
|
def send_post_api_request(properties, payload)
|
212
240
|
network_instance = NetworkManager.instance
|
@@ -225,20 +253,14 @@ class NetworkUtil
|
|
225
253
|
SettingsService.instance.port
|
226
254
|
)
|
227
255
|
|
228
|
-
begin
|
256
|
+
begin
|
229
257
|
if network_instance.get_client.get_should_use_threading
|
230
258
|
network_instance.get_client.get_thread_pool.post {
|
231
259
|
response = network_instance.post(request)
|
232
|
-
if response.get_status_code == 200
|
233
|
-
UsageStatsUtil.clear_usage_stats
|
234
|
-
end
|
235
260
|
response
|
236
261
|
}
|
237
262
|
else
|
238
263
|
response = network_instance.post(request)
|
239
|
-
if response.get_status_code == 200
|
240
|
-
UsageStatsUtil.clear_usage_stats
|
241
|
-
end
|
242
264
|
response
|
243
265
|
end
|
244
266
|
rescue ResponseModel => err
|
@@ -259,18 +281,23 @@ class NetworkUtil
|
|
259
281
|
headers[HeadersEnum::USER_AGENT] = payload[:d][:visitor_ua] if payload[:d][:visitor_ua]
|
260
282
|
headers[HeadersEnum::IP] = payload[:d][:visitor_ip] if payload[:d][:visitor_ip]
|
261
283
|
|
284
|
+
url = Constants::HOST_NAME
|
285
|
+
if UrlUtil.get_collection_prefix && !UrlUtil.get_collection_prefix.empty?
|
286
|
+
url = "#{url}/#{UrlUtil.get_collection_prefix}"
|
287
|
+
end
|
288
|
+
|
262
289
|
request = RequestModel.new(
|
263
|
-
|
290
|
+
url,
|
264
291
|
HttpMethodEnum::POST,
|
265
292
|
UrlEnum::EVENTS,
|
266
293
|
properties,
|
267
294
|
payload,
|
268
295
|
headers,
|
269
|
-
|
270
|
-
|
296
|
+
Constants::HTTPS_PROTOCOL,
|
297
|
+
nil
|
271
298
|
)
|
272
299
|
|
273
|
-
begin
|
300
|
+
begin
|
274
301
|
if network_instance.get_client.get_should_use_threading
|
275
302
|
network_instance.get_client.get_thread_pool.post {
|
276
303
|
response = network_instance.post(request)
|
@@ -287,7 +314,7 @@ class NetworkUtil
|
|
287
314
|
# Sends a GET API request to the specified endpoint with given properties
|
288
315
|
def send_get_api_request(properties, endpoint)
|
289
316
|
network_instance = NetworkManager.instance
|
290
|
-
|
317
|
+
|
291
318
|
request = RequestModel.new(
|
292
319
|
UrlUtil.get_base_url,
|
293
320
|
HttpMethodEnum::GET,
|
@@ -298,7 +325,7 @@ class NetworkUtil
|
|
298
325
|
SettingsService.Instance.protocol,
|
299
326
|
SettingsService.Instance.port
|
300
327
|
)
|
301
|
-
|
328
|
+
|
302
329
|
begin
|
303
330
|
network_instance.get(request)
|
304
331
|
rescue StandardError => err
|
@@ -309,4 +336,4 @@ class NetworkUtil
|
|
309
336
|
end
|
310
337
|
end
|
311
338
|
end
|
312
|
-
end
|
339
|
+
end
|
data/lib/vwo/utils/url_util.rb
CHANGED
@@ -69,6 +69,8 @@ class UsageStatsUtil
|
|
69
69
|
|
70
70
|
data = {}
|
71
71
|
|
72
|
+
data[:a] = SettingsService.instance.account_id
|
73
|
+
data[:env] = SettingsService.instance.sdk_key
|
72
74
|
data[:ig] = 1 if integrations
|
73
75
|
data[:eb] = 1 if event_batching
|
74
76
|
data[:gs] = 1 if gateway_service
|
@@ -84,7 +86,7 @@ class UsageStatsUtil
|
|
84
86
|
data[:ll] = LogLevelToNumber.to_number(logger[:level]) || -1
|
85
87
|
end
|
86
88
|
|
87
|
-
data[:pi] =
|
89
|
+
data[:pi] = poll_interval if poll_interval
|
88
90
|
|
89
91
|
if vwo_meta && vwo_meta.key?(:ea)
|
90
92
|
data[:_ea] = 1
|
data/lib/vwo.rb
CHANGED
@@ -93,6 +93,14 @@ class VWO
|
|
93
93
|
# send the sdk init info to vwo server
|
94
94
|
send_sdk_init_event(SettingsService.instance.settings_fetch_time, time_taken_for_init.to_s)
|
95
95
|
end
|
96
|
+
|
97
|
+
# send the usage stats event to vwo server
|
98
|
+
# get usage stats account id from settings
|
99
|
+
usage_stats_account_id = @@instance.original_settings["usageStatsAccountId"]
|
100
|
+
if usage_stats_account_id
|
101
|
+
send_sdk_usage_stats_event(usage_stats_account_id)
|
102
|
+
end
|
103
|
+
|
96
104
|
@@instance
|
97
105
|
rescue StandardError => e
|
98
106
|
puts "[ERROR]: VWO-SDK: Got error while initializing VWO: #{e.message}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vwo-fme-ruby-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VWO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-08-
|
11
|
+
date: 2025-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uuidtools
|