vwo-fme-ruby-sdk 1.4.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 314b352ba0d4578530e72be01599eee2846ed17f080adf40ddaadfe404d1a849
4
- data.tar.gz: 54f0126d7666337219026a5c47c046a9516c60ffa658ae8e3d45f379258dc946
3
+ metadata.gz: 070ef4b08bf92bddf7d91a7a520a570651ed5c79c2d792a73021889803589f46
4
+ data.tar.gz: 5a6bb42880b3d4e73da654d33c78e05566bd487c15205918bef6020447793454
5
5
  SHA512:
6
- metadata.gz: 7dcceb86720c7f1d8c763d0974beb710cca033724bf76f35a884b80f3c7bb12b3adea108b04fdccdc85f297e585ee9813bf64ce9a854313e15ee775f34d20780
7
- data.tar.gz: 21c80bd1c369b7344c93d3e72858fa4a47d4ad2199b9df63bf8c95371e92f39adcbd82012903ab26c7e09e1873e285d201229d040c0781fb1071f213ff4c2f9d
6
+ metadata.gz: 5f48860c62dd6c81743ee2647fe7144ba503bff54fc68f4ddb8619bde4ff698b13ba46db401f1ea40abffd30b4909b8ca0a42af628b9b2b71670eef15f54b215
7
+ data.tar.gz: dd3eaf38a66d744dd3e9f0b553e707610ae1b130980b1359eca5b9ae9ee70f063cfe4dd3a1c43a397676d52a2289e3770638ab1b076cdfc769b5bc72f5bb3f63
@@ -17,7 +17,7 @@
17
17
  # Define the Constants module
18
18
  module Constants
19
19
  SDK_NAME = 'vwo-fme-ruby-sdk'.freeze
20
- SDK_VERSION = '1.4.1'.freeze
20
+ SDK_VERSION = '1.5.0'.freeze
21
21
 
22
22
  MAX_TRAFFIC_PERCENT = 100
23
23
  MAX_TRAFFIC_VALUE = 10_000
@@ -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
- end
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
@@ -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
@@ -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
- sdk_key = SettingsService.instance.sdk_key || ''
85
- {
86
- en: event_name,
87
- a: SettingsService.instance.account_id,
88
- env: sdk_key,
89
- eTime: get_current_unix_timestamp_in_millis,
90
- random: get_random_number,
91
- p: 'FS',
92
- visitor_ua: visitor_user_agent || '',
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
- uuid = UUIDUtil.get_uuid(user_id.to_s, SettingsService.instance.account_id)
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
- d: {
105
- msgId: "#{uuid}-#{get_current_unix_timestamp_in_millis}",
106
- visId: uuid,
107
- sessionId: get_current_unix_timestamp,
108
- event: {
109
- props: {
110
- vwo_sdkName: Constants::SDK_NAME,
111
- vwo_sdkVersion: Constants::SDK_VERSION,
112
- vwo_envKey: sdk_key
113
- },
114
- name: event_name,
115
- time: get_current_unix_timestamp_in_millis
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,12 +156,6 @@ 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,
@@ -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
@@ -229,16 +257,10 @@ class NetworkUtil
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,15 +281,20 @@ 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
- UrlUtil.get_base_url,
290
+ url,
264
291
  HttpMethodEnum::POST,
265
292
  UrlEnum::EVENTS,
266
293
  properties,
267
294
  payload,
268
295
  headers,
269
- SettingsService.instance.protocol,
270
- SettingsService.instance.port
296
+ Constants::HTTPS_PROTOCOL,
297
+ nil
271
298
  )
272
299
 
273
300
  begin
@@ -42,5 +42,12 @@ class UrlUtil
42
42
 
43
43
  base_url
44
44
  end
45
+
46
+ # Retrieves the collection prefix.
47
+ #
48
+ # @return [String] The collection prefix.
49
+ def get_collection_prefix
50
+ @collection_prefix
51
+ end
45
52
  end
46
53
  end
@@ -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] = 1 if poll_interval
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.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-07 00:00:00.000000000 Z
11
+ date: 2025-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uuidtools