vwo-sdk 1.30.0 → 1.37.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vwo/constants.rb +3 -2
- data/lib/vwo/core/bucketer.rb +50 -48
- data/lib/vwo/core/variation_decider.rb +427 -428
- data/lib/vwo/enums.rb +17 -154
- data/lib/vwo/logger.rb +8 -5
- data/lib/vwo/schemas/settings_file.rb +7 -6
- data/lib/vwo/services/batch_events_dispatcher.rb +45 -38
- data/lib/vwo/services/batch_events_queue.rb +52 -68
- data/lib/vwo/services/event_dispatcher.rb +46 -16
- data/lib/vwo/services/hooks_manager.rb +8 -12
- data/lib/vwo/services/segment_evaluator.rb +17 -15
- data/lib/vwo/services/settings_file_manager.rb +5 -5
- data/lib/vwo/services/settings_file_processor.rb +7 -4
- data/lib/vwo/services/usage_stats.rb +5 -4
- data/lib/vwo/utils/campaign.rb +61 -64
- data/lib/vwo/utils/custom_dimensions.rb +14 -14
- data/lib/vwo/utils/data_location_manager.rb +2 -9
- data/lib/vwo/utils/feature.rb +7 -10
- data/lib/vwo/utils/impression.rb +80 -79
- data/lib/vwo/utils/log_message.rb +69 -0
- data/lib/vwo/utils/request.rb +7 -9
- data/lib/vwo/utils/utility.rb +45 -28
- data/lib/vwo/utils/uuid.rb +12 -10
- data/lib/vwo/utils/validations.rb +124 -49
- data/lib/vwo.rb +472 -620
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea72e150de33227c3e911fd61478a8815fb8f42f788df4a65a6751a1da7c25fb
|
4
|
+
data.tar.gz: c88b275817a6ef0ca80efc03287e57fd1488be9390e7a028a4dc812cca93abc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 294fab2cbb559b6869e547dd0f55b9bb5ac54910ba61d497f9d205fd37c405bc206b6264912bc0600306dd0986d875c034be0e4342260f3d0aa8a647ad0a67e3
|
7
|
+
data.tar.gz: d25b2e2642a1e178eeeba2b0f7f7e82188040df6116a6a14bb13abfba7cf8e0b2ee28c5161936cc9773663f55cdca9d371b72deea94393ac1c9d6a20cf9f383b
|
data/lib/vwo/constants.rb
CHANGED
@@ -19,7 +19,7 @@ class VWO
|
|
19
19
|
SEED_VALUE = 1
|
20
20
|
MAX_TRAFFIC_PERCENT = 100
|
21
21
|
MAX_TRAFFIC_VALUE = 10_000
|
22
|
-
MAX_RANGE =
|
22
|
+
MAX_RANGE = 10_000
|
23
23
|
STATUS_RUNNING = 'RUNNING'
|
24
24
|
# rubocop:disable Style/ExpandPathArguments
|
25
25
|
LIBRARY_PATH = File.expand_path('../..', __FILE__)
|
@@ -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.37.1'
|
31
31
|
SDK_NAME = 'ruby'
|
32
32
|
VWO_DELIMITER = '_vwo_'
|
33
33
|
MAX_EVENTS_PER_REQUEST = 5000
|
@@ -94,6 +94,7 @@ class VWO
|
|
94
94
|
}
|
95
95
|
|
96
96
|
module ApiMethods
|
97
|
+
LAUNCH = 'launch'
|
97
98
|
ACTIVATE = 'activate'
|
98
99
|
GET_VARIATION_NAME = 'get_variation_name'
|
99
100
|
TRACK = 'track'
|
data/lib/vwo/core/bucketer.rb
CHANGED
@@ -13,9 +13,9 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
require 'murmurhash3'
|
16
|
-
require_relative '../logger'
|
17
16
|
require_relative '../enums'
|
18
17
|
require_relative '../utils/validations'
|
18
|
+
require_relative '../utils/log_message'
|
19
19
|
require_relative '../constants'
|
20
20
|
|
21
21
|
class VWO
|
@@ -31,40 +31,46 @@ class VWO
|
|
31
31
|
# Source - https://stackoverflow.com/a/20766900/2494535
|
32
32
|
U_MAX_32_BIT = 0xFFFFFFFF
|
33
33
|
MAX_HASH_VALUE = 2**32
|
34
|
-
FILE = FileNameEnum::
|
34
|
+
FILE = FileNameEnum::BUCKETER
|
35
35
|
|
36
36
|
def initialize
|
37
|
-
@logger = VWO::Logger
|
37
|
+
@logger = VWO::Utils::Logger
|
38
38
|
end
|
39
39
|
|
40
40
|
# Calculate if this user should become part of the campaign or not
|
41
41
|
# @param[String] :user_id The unique ID assigned to a user
|
42
42
|
# @param[Dict] :campaign For getting traffic allotted to the campaign
|
43
|
+
# @param[Boolean] :disable_logs if true, do not log log-message
|
43
44
|
# @return[Boolean] If User is a part of Campaign or not
|
44
45
|
|
45
|
-
def user_part_of_campaign?(user_id, campaign)
|
46
|
+
def user_part_of_campaign?(user_id, campaign, disable_logs = false)
|
46
47
|
unless valid_value?(user_id)
|
47
48
|
@logger.log(
|
48
49
|
LogLevelEnum::ERROR,
|
49
|
-
|
50
|
+
'USER_ID_INVALID',
|
51
|
+
{
|
52
|
+
'{file}' => FILE,
|
53
|
+
'{userId}' => user_id
|
54
|
+
}
|
50
55
|
)
|
51
56
|
return false
|
52
57
|
end
|
53
58
|
|
54
|
-
if campaign.nil?
|
55
|
-
@logger.log(
|
56
|
-
LogLevelEnum::ERROR,
|
57
|
-
format(LogMessageEnum::ErrorMessages::INVALID_CAMPAIGN, file: FILE, method: 'is_user_part_of_campaign')
|
58
|
-
)
|
59
|
-
return false
|
60
|
-
end
|
59
|
+
return false if campaign.nil?
|
61
60
|
|
62
61
|
traffic_allocation = campaign['percentTraffic']
|
63
|
-
value_assigned_to_user = get_bucket_value_for_user(user_id, campaign)
|
62
|
+
value_assigned_to_user = get_bucket_value_for_user(user_id, campaign, nil, disable_logs)
|
64
63
|
is_user_part = (value_assigned_to_user != 0) && value_assigned_to_user <= traffic_allocation
|
65
64
|
@logger.log(
|
66
65
|
LogLevelEnum::INFO,
|
67
|
-
|
66
|
+
'USER_CAMPAIGN_ELIGIBILITY',
|
67
|
+
{
|
68
|
+
'{file}' => FILE,
|
69
|
+
'{userId}' => user_id,
|
70
|
+
'{status}' => is_user_part ? 'eligible' : 'not eligible',
|
71
|
+
'{campaignKey}' => campaign['key']
|
72
|
+
},
|
73
|
+
disable_logs
|
68
74
|
)
|
69
75
|
is_user_part
|
70
76
|
end
|
@@ -74,30 +80,27 @@ class VWO
|
|
74
80
|
#
|
75
81
|
# @param[String] :user_id The unique ID assigned to User
|
76
82
|
# @param[Hash] :campaign The Campaign of which User is a part of
|
83
|
+
# @param[Boolean] :disable_logs if true, do not log log-message
|
77
84
|
#
|
78
85
|
# @return[Hash|nil} Variation data into which user is bucketed to
|
79
86
|
# or nil if not
|
80
|
-
def bucket_user_to_variation(user_id, campaign)
|
87
|
+
def bucket_user_to_variation(user_id, campaign, disable_logs = false)
|
81
88
|
unless valid_value?(user_id)
|
82
89
|
@logger.log(
|
83
90
|
LogLevelEnum::ERROR,
|
84
|
-
|
91
|
+
'USER_ID_INVALID',
|
92
|
+
{
|
93
|
+
'{file}' => FILE,
|
94
|
+
'{userId}' => user_id
|
95
|
+
}
|
85
96
|
)
|
86
97
|
return
|
87
98
|
end
|
88
99
|
|
89
|
-
unless campaign
|
90
|
-
@logger.log(
|
91
|
-
LogLevelEnum::ERROR,
|
92
|
-
format(LogMessageEnum::ErrorMessages::INVALID_CAMPAIGN, file: FILE, method: 'is_user_part_of_campaign')
|
93
|
-
)
|
94
|
-
return
|
95
|
-
end
|
100
|
+
return unless campaign
|
96
101
|
|
97
102
|
user_id_for_hash_value = user_id
|
98
|
-
if campaign['isBucketingSeedEnabled']
|
99
|
-
user_id_for_hash_value = campaign['id'].to_s + "_" + user_id
|
100
|
-
end
|
103
|
+
user_id_for_hash_value = "#{campaign['id']}_#{user_id}" if campaign['isBucketingSeedEnabled']
|
101
104
|
hash_value = MurmurHash3::V32.str_hash(user_id_for_hash_value, SEED_VALUE) & U_MAX_32_BIT
|
102
105
|
normalize = MAX_TRAFFIC_VALUE.to_f / campaign['percentTraffic']
|
103
106
|
multiplier = normalize / 100
|
@@ -109,15 +112,16 @@ class VWO
|
|
109
112
|
|
110
113
|
@logger.log(
|
111
114
|
LogLevelEnum::DEBUG,
|
112
|
-
|
113
|
-
|
114
|
-
file
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
115
|
+
'USER_CAMPAIGN_BUCKET_VALUES',
|
116
|
+
{
|
117
|
+
'{file}' => FILE,
|
118
|
+
'{campaignKey}' => campaign['key'],
|
119
|
+
'{userId}' => user_id,
|
120
|
+
'{percentTraffic}' => campaign['percentTraffic'],
|
121
|
+
'{hashValue}' => hash_value,
|
122
|
+
'{bucketValue}' => bucket_value
|
123
|
+
},
|
124
|
+
disable_logs
|
121
125
|
)
|
122
126
|
|
123
127
|
get_variation(campaign['variations'], bucket_value)
|
@@ -146,22 +150,22 @@ class VWO
|
|
146
150
|
def get_bucket_value_for_user(user_id, campaign = {}, group_id = nil, disable_logs = false)
|
147
151
|
user_id_for_hash_value = user_id
|
148
152
|
if group_id
|
149
|
-
user_id_for_hash_value = group_id
|
153
|
+
user_id_for_hash_value = "#{group_id}_#{user_id}"
|
150
154
|
elsif campaign['isBucketingSeedEnabled']
|
151
|
-
user_id_for_hash_value = campaign['id']
|
155
|
+
user_id_for_hash_value = "#{campaign['id']}_#{user_id}"
|
152
156
|
end
|
153
157
|
hash_value = MurmurHash3::V32.str_hash(user_id_for_hash_value, SEED_VALUE) & U_MAX_32_BIT
|
154
158
|
bucket_value = get_bucket_value(hash_value, MAX_TRAFFIC_PERCENT)
|
155
159
|
|
156
160
|
@logger.log(
|
157
161
|
LogLevelEnum::DEBUG,
|
158
|
-
|
159
|
-
|
160
|
-
file
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
162
|
+
'USER_HASH_BUCKET_VALUE',
|
163
|
+
{
|
164
|
+
'{file}' => FILE,
|
165
|
+
'{hashValue}' => hash_value,
|
166
|
+
'{userId}' => user_id,
|
167
|
+
'{bucketValue}' => bucket_value
|
168
|
+
},
|
165
169
|
disable_logs
|
166
170
|
)
|
167
171
|
bucket_value
|
@@ -188,11 +192,9 @@ class VWO
|
|
188
192
|
# @return[Hash|nil]
|
189
193
|
#
|
190
194
|
def get_campaign_using_range(range_for_campaigns, campaigns)
|
191
|
-
range_for_campaigns
|
195
|
+
range_for_campaigns *= 100
|
192
196
|
campaigns.each do |campaign|
|
193
|
-
if campaign[
|
194
|
-
return campaign
|
195
|
-
end
|
197
|
+
return campaign if campaign['max_range'] && campaign['max_range'] >= range_for_campaigns && campaign['min_range'] <= range_for_campaigns
|
196
198
|
end
|
197
199
|
nil
|
198
200
|
end
|