vwo-sdk 1.15.0 → 1.23.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2307340499cf5f0fd3fd13ab5025fc4892721123c82bc3df8eff266362d01c82
4
- data.tar.gz: a0a3343ef9af102444cd9a6dd590937d5c737a3ed46765d3bd9cb8e18ceb41bf
3
+ metadata.gz: f36297d491673769eab11fc07c0c33388da361b564fc1888a078f251a53a695e
4
+ data.tar.gz: e1ef625b6ed40c6223d90a019f35e276fc6c5252e91b004f68d1ffab5fd72d41
5
5
  SHA512:
6
- metadata.gz: f1c28b3c5b86fa2b4488b5995a9931aaea708d1788f803c079f2fc5684fca81d82465f798e9653d227d448d6c08688791cf0740f774526ed38bd345e252b91fa
7
- data.tar.gz: e4d2fcfca37407b7ed7ff008bc2d2d6b03e7f6bddd2f653825fd059306de36254ee4d46165e0973524e701d62e9a972c11a586089c5279027fb4ea5dc589060f
6
+ metadata.gz: ec99893b52fad4cdfb156d8d46b69c3b2f526fb25f0bfda2c27205f938fe3918853edb969534256edb47d16100fc54cd1061924a5bd24097aea256b649c80431
7
+ data.tar.gz: 73572a0f681bde9fd8f03b426097a4ee1bda9d8acda8048260f839559b3a20497f52f4c94dc6b28f41abde5a0fd91e4f31f2dc62031a423f7409970f1cfe8048
data/lib/vwo/constants.rb CHANGED
@@ -19,6 +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 = 10000
22
23
  STATUS_RUNNING = 'RUNNING'
23
24
  # rubocop:disable Style/ExpandPathArguments
24
25
  LIBRARY_PATH = File.expand_path('../..', __FILE__)
@@ -26,7 +27,7 @@ class VWO
26
27
  HTTP_PROTOCOL = 'http://'
27
28
  HTTPS_PROTOCOL = 'https://'
28
29
  URL_NAMESPACE = '6ba7b811-9dad-11d1-80b4-00c04fd430c8'
29
- SDK_VERSION = '1.15.0'
30
+ SDK_VERSION = '1.23.1'
30
31
  SDK_NAME = 'ruby'
31
32
  VWO_DELIMITER = '_vwo_'
32
33
  MAX_EVENTS_PER_REQUEST = 5000
@@ -68,6 +69,7 @@ class VWO
68
69
  INTEGER = 'integer'
69
70
  DOUBLE = 'double'
70
71
  BOOLEAN = 'boolean'
72
+ JSON = 'json'
71
73
  end
72
74
 
73
75
  module Hooks
@@ -80,7 +82,8 @@ class VWO
80
82
  'string' => [String],
81
83
  'integer' => [Integer],
82
84
  'double' => [Float],
83
- 'boolean' => [TrueClass, FalseClass]
85
+ 'boolean' => [TrueClass, FalseClass],
86
+ 'json' => [Hash]
84
87
  }
85
88
 
86
89
  GOAL_TYPES = {
@@ -60,7 +60,7 @@ class VWO
60
60
  end
61
61
 
62
62
  traffic_allocation = campaign['percentTraffic']
63
- value_assigned_to_user = get_bucket_value_for_user(user_id)
63
+ value_assigned_to_user = get_bucket_value_for_user(user_id, campaign)
64
64
  is_user_part = (value_assigned_to_user != 0) && value_assigned_to_user <= traffic_allocation
65
65
  @logger.log(
66
66
  LogLevelEnum::INFO,
@@ -94,7 +94,11 @@ class VWO
94
94
  return
95
95
  end
96
96
 
97
- hash_value = MurmurHash3::V32.str_hash(user_id, SEED_VALUE) & U_MAX_32_BIT
97
+ 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
101
+ hash_value = MurmurHash3::V32.str_hash(user_id_for_hash_value, SEED_VALUE) & U_MAX_32_BIT
98
102
  normalize = MAX_TRAFFIC_VALUE.to_f / campaign['percentTraffic']
99
103
  multiplier = normalize / 100
100
104
  bucket_value = get_bucket_value(
@@ -136,10 +140,17 @@ class VWO
136
140
  # User by hashing the userId by murmurHash and scaling it down.
137
141
  #
138
142
  # @param[String] :user_id The unique ID assigned to User
143
+ # @param[String] :campaign Campaign data
139
144
  # @return[Integer] The bucket Value allotted to User
140
145
  # (between 1 to $this->$MAX_TRAFFIC_PERCENT)
141
- def get_bucket_value_for_user(user_id)
142
- hash_value = MurmurHash3::V32.str_hash(user_id, SEED_VALUE) & U_MAX_32_BIT
146
+ def get_bucket_value_for_user(user_id, campaign = {}, group_id = nil, disable_logs = false)
147
+ user_id_for_hash_value = user_id
148
+ if group_id
149
+ user_id_for_hash_value = group_id.to_s + "_" + user_id
150
+ elsif campaign[:isBucketingSeedEnabled]
151
+ user_id_for_hash_value = campaign[:id].to_s + "_" + user_id
152
+ end
153
+ hash_value = MurmurHash3::V32.str_hash(user_id_for_hash_value, SEED_VALUE) & U_MAX_32_BIT
143
154
  bucket_value = get_bucket_value(hash_value, MAX_TRAFFIC_PERCENT)
144
155
 
145
156
  @logger.log(
@@ -150,7 +161,8 @@ class VWO
150
161
  hash_value: hash_value,
151
162
  bucket_value: bucket_value,
152
163
  user_id: user_id
153
- )
164
+ ),
165
+ disable_logs
154
166
  )
155
167
  bucket_value
156
168
  end
@@ -168,6 +180,22 @@ class VWO
168
180
  multiplied_value = (max_value * ratio + 1) * multiplier
169
181
  multiplied_value.to_i
170
182
  end
183
+
184
+ # Returns a campaign by checking the Start and End Bucket Allocations of each campaign.
185
+ #
186
+ # @param[Integer] :range_for_campaigns the bucket value of the user
187
+ # @param[Hash] :campaigns The bucket Value of the user
188
+ # @return[Hash|nil]
189
+ #
190
+ def get_campaign_using_range(range_for_campaigns, campaigns)
191
+ range_for_campaigns = range_for_campaigns * 100
192
+ campaigns.each do |campaign|
193
+ if campaign["max_range"] && campaign["max_range"] >= range_for_campaigns && campaign["min_range"] <= range_for_campaigns
194
+ return campaign
195
+ end
196
+ end
197
+ nil
198
+ end
171
199
  end
172
200
  end
173
201
  end