vwo-sdk 1.14.1 → 1.23.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/vwo/enums.rb CHANGED
@@ -113,6 +113,7 @@ class VWO
113
113
  BULK_NOT_PROCESSED = "(%<file>s): Batch events couldn't be received by VWO. Calling Flush Callback with error and data."
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
+ 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"
116
117
  end
117
118
 
118
119
  # Info Messages
@@ -152,9 +153,13 @@ class VWO
152
153
  CAMPAIGN_NOT_ACTIVATED = '(%<file>s): Activate the campaign:%<campaign_key>s for User ID:%<user_id>s to %<reason>s.'
153
154
  GOAL_ALREADY_TRACKED = '(%<file>s): Goal:%<goal_identifier>s of Campaign:%<campaign_key>s for User ID:%<user_id>s has already been tracked earlier. Skipping now'
154
155
  USER_ALREADY_TRACKED = '(%<file>s): User ID:%<user_id>s for Campaign:%<campaign_key>s has already been tracked earlier for "%<api_name>s" API. Skipping now'
155
- API_CALLED = '(%<file>s): API: {api_name} called for UserId:%<user_id>s'
156
+ API_CALLED = '(%<file>s): API: %<api_name>s called for UserId:%<user_id>s'
156
157
  BULK_IMPRESSION_SUCCESS = '(%<file>s): Impression event - %<end_point>s was successfully received by VWO having accountId:%<a>s'
157
158
  AFTER_FLUSHING = '(%<file>s): Events queue having %<length>s events has been flushed %<manually>s queue summary: %<queue_metadata>s'
159
+ GOT_WINNER_CAMPAIGN = "(%<file>s): Campaign:%<campaign_key>s is selected from the mutually exclusive group:%<group_name>s for the User ID:%<user_id>s"
160
+ GOT_ELIGIBLE_CAMPAIGNS = "(%<file>s): Got %<no_of_eligible_campaigns>s eligible winners out of %<no_of_group_campaigns>s from the Group:%<group_name>s and for User ID:%<user_id>s"
161
+ CALLED_CAMPAIGN_NOT_WINNER = "(%<file>s): Campaign:%<campaign_key>s does not qualify from the mutually exclusive group:%<group_name>s for User ID:%<user_id>s"
162
+ OTHER_CAMPAIGN_SATISFIES_WHITELISTING_OR_STORAGE = "(%<file>s): Campaign:%<campaign_key>s of Group:%<group_name>s satisfies %<type>s for User ID:%<user_id>s"
158
163
  end
159
164
 
160
165
  # Warning Messages
data/lib/vwo/logger.rb CHANGED
@@ -28,8 +28,10 @@ class VWO
28
28
  end
29
29
 
30
30
  # Override this method to handle logs in a custom manner
31
- def log(level, message)
32
- @@logger_instance.log(level, message)
31
+ def log(level, message, disable_logs = false)
32
+ unless disable_logs
33
+ @@logger_instance.log(level, message)
34
+ end
33
35
  end
34
36
 
35
37
  def instance
@@ -54,7 +54,13 @@ class VWO
54
54
  },
55
55
  weight: {
56
56
  type: %w[number string]
57
- }
57
+ },
58
+ variables: {
59
+ type: 'array',
60
+ items: {
61
+ '$ref' => '#/definitions/variables_schema'
62
+ }
63
+ }
58
64
  },
59
65
  required: %w[id name weight]
60
66
  },
@@ -79,9 +85,34 @@ class VWO
79
85
  '$ref' => '#/definitions/campaign_variation_schema'
80
86
  }
81
87
  },
88
+ variables: {
89
+ type: 'array',
90
+ items: {
91
+ '$ref' => '#/definitions/variables_schema'
92
+ }
93
+ },
94
+ isBucketingSeedEnabled: ['boolean'],
82
95
  minItems: 2
83
96
  }
84
97
  },
98
+ variables_schema: {
99
+ type: 'object',
100
+ properties: {
101
+ id: {
102
+ type: %w[number string]
103
+ },
104
+ key: {
105
+ type: ['string']
106
+ },
107
+ type: {
108
+ type: ['string']
109
+ },
110
+ value: {
111
+ type: %w[number string boolean double object]
112
+ }
113
+ },
114
+ required: %w[id key type value]
115
+ },
85
116
  required: %w[
86
117
  id
87
118
  key
@@ -91,11 +91,10 @@ class VWO
91
91
  # @return [Boolean]
92
92
  def evaluate_custom_variable?(operand, custom_variables)
93
93
  # Extract custom_variable_key and custom_variables_value from operand
94
-
95
94
  operand_key, operand = get_key_value(operand)
96
95
 
97
96
  # Retrieve corresponding custom_variable value from custom_variables
98
- custom_variables_value = custom_variables[operand_key]
97
+ custom_variables_value = custom_variables[operand_key.to_sym]
99
98
 
100
99
  # Pre process custom_variable value
101
100
  custom_variables_value = process_custom_variables_value(custom_variables_value)
@@ -113,7 +112,7 @@ class VWO
113
112
  def evaluate_user?(operand, custom_variables)
114
113
  users = operand.split(',')
115
114
  users.each do |user|
116
- return true if user.strip == custom_variables['_vwo_user_id']
115
+ return true if user.strip == custom_variables[:_vwo_user_id]
117
116
  end
118
117
  false
119
118
  end
@@ -63,10 +63,11 @@ class VWO
63
63
  # @param[String] :user_id Unique user identifier
64
64
  # @param[Hash] :dsl Segments provided in the settings_file
65
65
  # @param[Hash] :custom_variables Custom variables provided in the apis
66
+ # @param[Boolean] :disable_logs disable logs if True
66
67
  #
67
68
  # @return[Boolean] true if user passed pre-segmentation, else false
68
69
  #
69
- def evaluate(campaign_key, user_id, dsl, custom_variables)
70
+ def evaluate(campaign_key, user_id, dsl, custom_variables, disable_logs = false)
70
71
  result = evaluate_util(dsl, custom_variables) if valid_value?(dsl)
71
72
  result
72
73
  rescue StandardError => e
@@ -79,7 +80,8 @@ class VWO
79
80
  campaign_key: campaign_key,
80
81
  custom_variables: custom_variables,
81
82
  error_message: e
82
- )
83
+ ),
84
+ disable_logs
83
85
  )
84
86
  false
85
87
  end
@@ -57,6 +57,26 @@ class VWO
57
57
  end
58
58
  end
59
59
 
60
+ # Sets campaign allocation range in the provided campaigns list
61
+ #
62
+ # @param [Array]: Array of Campaigns
63
+ def set_campaign_allocation(campaigns)
64
+ current_allocation = 0
65
+ campaigns.each do |campaign|
66
+ step_factor = get_variation_bucketing_range(campaign['weight'])
67
+ if step_factor > 0
68
+ start_range = current_allocation + 1
69
+ end_range = current_allocation + step_factor
70
+ campaign['min_range'] = start_range
71
+ campaign['max_range'] = end_range
72
+ current_allocation += step_factor
73
+ else
74
+ campaign['min_range'] = -1
75
+ campaign['max_range'] = -1
76
+ end
77
+ end
78
+ end
79
+
60
80
  # Returns goal from given campaign_key and gaol_identifier.
61
81
  # @param[String] :campaign Campaign object
62
82
  # @param[String] :goal_identifier Goal identifier
@@ -190,7 +210,7 @@ class VWO
190
210
  end
191
211
  goal = get_campaign_goal(campaign, goal_identifier)
192
212
  if validate_goal(goal, goal_type_to_track)
193
- campaigns.append(campaign)
213
+ campaigns.push(campaign)
194
214
  end
195
215
  end
196
216
  end
@@ -215,7 +235,7 @@ class VWO
215
235
 
216
236
  campaign = get_campaign_for_campaign_key_and_goal(campaign_key, settings_file, goal_identifier, goal_type_to_track)
217
237
  if campaign
218
- campaigns.append(campaign)
238
+ campaigns.push(campaign)
219
239
  end
220
240
  end
221
241
  campaigns
@@ -249,6 +269,44 @@ class VWO
249
269
  return campaign
250
270
  end
251
271
 
272
+ # Checks whether a campaign is part of a group.
273
+ #
274
+ # @param[Hash] :settings_file Settings file for the project
275
+ # @param[Integer] :campaign_id Id of campaign which is to be checked
276
+ # @return[Boolean]
277
+ def is_part_of_group(settings_file, campaign_id)
278
+ if settings_file["campaignGroups"] && (settings_file["campaignGroups"].has_key?(campaign_id.to_s))
279
+ return true
280
+ end
281
+ false
282
+ end
283
+
284
+ # Returns campaigns which are part of given group using group_id.
285
+ #
286
+ # @param[Hash] :settings_file Settings file for the project
287
+ # @param[Integer] :group_id id of group whose campaigns are to be return
288
+ # @return[Array]
289
+ def get_group_campaigns(settings_file, group_id)
290
+ group_campaign_ids = []
291
+ group_campaigns = []
292
+ groups = settings_file["groups"]
293
+
294
+ if groups && groups.has_key?(group_id.to_s)
295
+ group_campaign_ids = groups[group_id.to_s]["campaigns"]
296
+ end
297
+
298
+ if group_campaign_ids
299
+ group_campaign_ids.each do |campaign_id|
300
+ settings_file["campaigns"].each do |campaign|
301
+ if campaign["id"] == campaign_id && campaign["status"] == STATUS_RUNNING
302
+ group_campaigns.push(campaign)
303
+ end
304
+ end
305
+ end
306
+ end
307
+ group_campaigns
308
+ end
309
+
252
310
  end
253
311
  end
254
312
  end
@@ -38,6 +38,8 @@ class VWO
38
38
  return value.to_f if variable_type == VariableTypes::DOUBLE
39
39
 
40
40
  return !value || value == 0 ? false : true if variable_type == VariableTypes.BOOLEAN
41
+
42
+ return value if variable_type == VariableTypes::JSON
41
43
  rescue StandardError => _e
42
44
  VWO::Logger.get_instance.log(
43
45
  LogLevelEnum::ERROR,
@@ -0,0 +1,40 @@
1
+ # Copyright 2019-2021 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'json'
16
+ require_relative './validations'
17
+
18
+ # Generic utility module
19
+ class VWO
20
+ module Utils
21
+ module Utility
22
+ include Validations
23
+
24
+ # converting hash with keys as strings into hash with keys as strings
25
+ # @param[Hash]
26
+ # @return[Hash]
27
+ def convert_to_symbol_hash(hashObject)
28
+ convertedHash = {}
29
+ hashObject.each do |key, value|
30
+ if valid_hash?(value)
31
+ convertedHash[key.to_sym] = convert_to_symbol_hash(value)
32
+ else
33
+ convertedHash[key.to_sym] = value
34
+ end
35
+ end
36
+ convertedHash
37
+ end
38
+ end
39
+ end
40
+ end