vwo-sdk 1.30.0 → 1.35.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/vwo.rb CHANGED
@@ -25,6 +25,7 @@ require_relative 'vwo/utils/feature'
25
25
  require_relative 'vwo/utils/custom_dimensions'
26
26
  require_relative 'vwo/utils/utility'
27
27
  require_relative 'vwo/utils/data_location_manager'
28
+ require_relative 'vwo/utils/log_message'
28
29
  require_relative 'vwo/constants'
29
30
  require_relative 'vwo/core/variation_decider'
30
31
  require_relative 'vwo/services/batch_events_dispatcher'
@@ -33,7 +34,7 @@ require_relative 'vwo/services/usage_stats'
33
34
 
34
35
  # VWO main file
35
36
  class VWO
36
- attr_accessor :is_instance_valid, :logger, :settings_file_manager, :variation_decider
37
+ attr_accessor :is_instance_valid, :logging, :settings_file_manager, :variation_decider
37
38
  attr_reader :usage_stats
38
39
  include Enums
39
40
  include Utils::Validations
@@ -66,14 +67,16 @@ class VWO
66
67
  settings_file = nil,
67
68
  options = {}
68
69
  )
70
+ @logger = Utils::Logger
71
+ @logger.set_api_name(ApiMethods::LAUNCH)
69
72
  options = convert_to_symbol_hash(options)
70
73
  @is_opted_out = false
71
74
  @account_id = account_id
72
75
  @sdk_key = sdk_key
73
76
  @user_storage = user_storage
74
77
  @is_development_mode = is_development_mode
75
- @logger = VWO::Logger.get_instance(logger)
76
- @logger.instance.level = options[:log_level] if (0..5).include?(options[:log_level])
78
+ @logging = VWO::Logger.get_instance(logger)
79
+ @logging.instance.level = options[:log_level] if (0..5).include?(options[:log_level])
77
80
  usage_stats = {}
78
81
 
79
82
  usage_stats[:cl] = 1 if logger
@@ -82,11 +85,19 @@ class VWO
82
85
  usage_stats[:ig] = 1 if options.key?(:integrations)
83
86
  usage_stats[:eb] = 1 if options.key?(:batch_events)
84
87
 
88
+ unless validate_sdk_config?(@user_storage, is_development_mode, ApiMethods::LAUNCH)
89
+ @is_instance_valid = false
90
+ return
91
+ end
92
+
85
93
  @settings_file_manager = VWO::Services::SettingsFileManager.new(@account_id, @sdk_key)
86
94
  unless valid_settings_file?(get_settings(settings_file))
87
95
  @logger.log(
88
96
  LogLevelEnum::ERROR,
89
- format(LogMessageEnum::ErrorMessages::SETTINGS_FILE_CORRUPTED, file: FILE)
97
+ 'SETTINGS_FILE_CORRUPTED',
98
+ {
99
+ '{file}' => FILE
100
+ }
90
101
  )
91
102
  @is_instance_valid = false
92
103
  return
@@ -99,10 +110,13 @@ class VWO
99
110
  else
100
111
  @logger.log(
101
112
  LogLevelEnum::ERROR,
102
- format(
103
- LogMessageEnum::ErrorMessages::INVALID_GOAL_TYPE,
104
- file: FILE
105
- )
113
+ 'CONFIG_PARAMETER_INVALID',
114
+ {
115
+ '{file}' => FILE,
116
+ '{parameter}' => 'goal_type_to_track',
117
+ '{type}' => 'string(REVENUE, CUSTOM, ALL)',
118
+ '{api}' => 'init'
119
+ }
106
120
  )
107
121
  @is_instance_valid = false
108
122
  return
@@ -114,15 +128,7 @@ class VWO
114
128
  @is_instance_valid = true
115
129
  @config = VWO::Services::SettingsFileProcessor.new(get_settings)
116
130
 
117
- @logger.log(
118
- LogLevelEnum::DEBUG,
119
- format(
120
- LogMessageEnum::DebugMessages::VALID_CONFIGURATION,
121
- file: FILE
122
- )
123
- )
124
-
125
- # Process the settings file
131
+ #Process the settings file
126
132
  @config.process_settings_file
127
133
  @settings_file = @config.get_settings_file
128
134
  DataLocationManager.get_instance().set_settings(@settings_file)
@@ -131,11 +137,11 @@ class VWO
131
137
 
132
138
  if options.key?(:batch_events)
133
139
  if options[:batch_events].is_a?(Hash)
134
- unless is_valid_batch_event_settings(options[:batch_events])
140
+ unless is_valid_batch_event_settings(options[:batch_events], ApiMethods::LAUNCH)
135
141
  @is_instance_valid = false
136
142
  return
137
143
  end
138
- @batch_event_dispatcher = VWO::Services::BatchEventsDispatcher.new
144
+ @batch_event_dispatcher = VWO::Services::BatchEventsDispatcher.new(@is_development_mode)
139
145
  def dispatcher (events, callback)
140
146
  @batch_event_dispatcher.dispatch(
141
147
  {
@@ -163,10 +169,13 @@ class VWO
163
169
  else
164
170
  @logger.log(
165
171
  LogLevelEnum::ERROR,
166
- format(
167
- LogMessageEnum::ErrorMessages::EVENT_BATCHING_NOT_OBJECT,
168
- file: FILE
169
- )
172
+ 'CONFIG_PARAMETER_INVALID',
173
+ {
174
+ '{file}' => FILE,
175
+ '{parameter}' => 'batch_events',
176
+ '{type}' => 'hash',
177
+ '{api}' => 'init'
178
+ }
170
179
  )
171
180
  @is_instance_valid = false
172
181
  return
@@ -176,25 +185,14 @@ class VWO
176
185
  # Assign VariationDecider to VWO
177
186
  @variation_decider = VWO::Core::VariationDecider.new(@settings_file, user_storage, options)
178
187
 
179
- if is_development_mode
180
- @logger.log(
181
- LogLevelEnum::DEBUG,
182
- format(
183
- LogMessageEnum::DebugMessages::SET_DEVELOPMENT_MODE,
184
- file: FILE
185
- )
186
- )
187
- end
188
188
  # Assign event dispatcher
189
189
  @event_dispatcher = VWO::Services::EventDispatcher.new(is_development_mode)
190
190
 
191
191
  # Successfully initialized VWO SDK
192
192
  @logger.log(
193
- LogLevelEnum::DEBUG,
194
- format(
195
- LogMessageEnum::DebugMessages::SDK_INITIALIZED,
196
- file: FILE
197
- )
193
+ LogLevelEnum::INFO,
194
+ 'SDK_INITIALIZED',
195
+ {'{file}' => FILE}
198
196
  )
199
197
  end
200
198
 
@@ -211,7 +209,7 @@ class VWO
211
209
 
212
210
  # VWO get_settings method to get settings for a particular account_id
213
211
  def get_and_update_settings_file
214
-
212
+ @logger.set_api_name(ApiMethods::GET_AND_UPDATE_SETTINGS_FILE)
215
213
  if is_opted_out(ApiMethods::GET_AND_UPDATE_SETTINGS_FILE)
216
214
  return false
217
215
  end
@@ -219,11 +217,11 @@ class VWO
219
217
  unless @is_instance_valid
220
218
  @logger.log(
221
219
  LogLevelEnum::ERROR,
222
- format(
223
- LogMessageEnum::ErrorMessages::API_CONFIG_CORRUPTED,
224
- file: FILE,
225
- api_name: ApiMethods.GET_AND_UPDATE_SETTINGS_FILE
226
- )
220
+ 'CONFIG_CORRUPTED',
221
+ {
222
+ '{file}' => FILE,
223
+ '{api}' => ApiMethods::GET_AND_UPDATE_SETTINGS_FILE
224
+ }
227
225
  )
228
226
  return false
229
227
  end
@@ -232,12 +230,12 @@ class VWO
232
230
  latest_settings = JSON.parse(latest_settings)
233
231
  if latest_settings == @settings_file
234
232
  @logger.log(
235
- LogLevelEnum::INFO,
236
- format(
237
- LogMessageEnum::InfoMessages::SETTINGS_NOT_UPDATED,
238
- api_name: ApiMethods::GET_AND_UPDATE_SETTINGS_FILE,
239
- file: FILE
240
- )
233
+ LogLevelEnum::DEBUG,
234
+ 'SETTINGS_FILE_PROCESSED',
235
+ {
236
+ '{file}' => FILE,
237
+ '{accountId}' => @settings_file['accountId']
238
+ }
241
239
  )
242
240
  end
243
241
 
@@ -247,12 +245,11 @@ class VWO
247
245
  rescue StandardError => e
248
246
  @logger.log(
249
247
  LogLevelEnum::ERROR,
250
- format(
251
- LogMessageEnum::ErrorMessages::API_NOT_WORKING,
252
- file: FILE,
253
- api_name: ApiMethods::GET_AND_UPDATE_SETTINGS_FILE,
254
- exception: e
255
- )
248
+ '({file}): {api} API error: ' + e.message,
249
+ {
250
+ '{file}' => FILE,
251
+ '{api}' => ApiMethods::GET_AND_UPDATE_SETTINGS_FILE
252
+ }
256
253
  )
257
254
  nil
258
255
  end
@@ -275,6 +272,7 @@ class VWO
275
272
  # otherwise null in case of user not becoming part
276
273
 
277
274
  def activate(campaign_key, user_id, options = {})
275
+ @logger.set_api_name(ApiMethods::ACTIVATE)
278
276
  if is_opted_out(ApiMethods::ACTIVATE)
279
277
  return nil
280
278
  end
@@ -282,11 +280,11 @@ class VWO
282
280
  unless @is_instance_valid
283
281
  @logger.log(
284
282
  LogLevelEnum::ERROR,
285
- format(
286
- LogMessageEnum::ErrorMessages::API_CONFIG_CORRUPTED,
287
- file: FILE,
288
- api_name: ApiMethods::ACTIVATE
289
- )
283
+ 'CONFIG_CORRUPTED',
284
+ {
285
+ '{file}' => FILE,
286
+ '{api}' => ApiMethods::ACTIVATE
287
+ }
290
288
  )
291
289
  return
292
290
  end
@@ -301,11 +299,11 @@ class VWO
301
299
  (variation_targeting_variables.nil? || valid_hash?(variation_targeting_variables))
302
300
  @logger.log(
303
301
  LogLevelEnum::ERROR,
304
- format(
305
- LogMessageEnum::ErrorMessages::ACTIVATE_API_MISSING_PARAMS,
306
- api_name: ApiMethods::ACTIVATE,
307
- file: FILE
308
- )
302
+ 'API_BAD_PARAMETERS',
303
+ {
304
+ '{file}' => FILE,
305
+ '{api}' => ApiMethods::ACTIVATE
306
+ }
309
307
  )
310
308
  return
311
309
  end
@@ -317,13 +315,13 @@ class VWO
317
315
  unless campaign && campaign['status'] == STATUS_RUNNING
318
316
  # Log Campaign as invalid
319
317
  @logger.log(
320
- LogLevelEnum::ERROR,
321
- format(
322
- LogMessageEnum::ErrorMessages::CAMPAIGN_NOT_RUNNING,
323
- file: FILE,
324
- campaign_key: campaign_key,
325
- api_name: ApiMethods::ACTIVATE
326
- )
318
+ LogLevelEnum::WARNING,
319
+ 'CAMPAIGN_NOT_RUNNING',
320
+ {
321
+ '{file}' => FILE,
322
+ '{campaignKey}' => campaign_key,
323
+ '{api}' => ApiMethods::ACTIVATE
324
+ }
327
325
  )
328
326
  return
329
327
  end
@@ -335,14 +333,14 @@ class VWO
335
333
  if campaign_type != CampaignTypes::VISUAL_AB
336
334
  @logger.log(
337
335
  LogLevelEnum::ERROR,
338
- format(
339
- LogMessageEnum::ErrorMessages::INVALID_API,
340
- file: FILE,
341
- api_name: ApiMethods::ACTIVATE,
342
- user_id: user_id,
343
- campaign_key: campaign_key,
344
- campaign_type: campaign_type
345
- )
336
+ 'API_NOT_APPLICABLE',
337
+ {
338
+ '{file}' => FILE,
339
+ '{api}' => ApiMethods::ACTIVATE,
340
+ '{userId}' => user_id,
341
+ '{campaignKey}' => campaign_key,
342
+ '{campaignType}' => campaign_type,
343
+ }
346
344
  )
347
345
  return
348
346
  end
@@ -361,15 +359,6 @@ class VWO
361
359
 
362
360
  # Check if variation_name has been assigned
363
361
  if variation.nil?
364
- @logger.log(
365
- LogLevelEnum::INFO,
366
- format(
367
- LogMessageEnum::InfoMessages::INVALID_VARIATION_KEY,
368
- file: FILE,
369
- user_id: user_id,
370
- campaign_key: campaign_key
371
- )
372
- )
373
362
  return
374
363
  end
375
364
 
@@ -401,39 +390,37 @@ class VWO
401
390
  if @event_dispatcher.dispatch(impression)
402
391
  @logger.log(
403
392
  LogLevelEnum::INFO,
404
- format(
405
- LogMessageEnum::InfoMessages::IMPRESSION_SUCCESS,
406
- file: FILE,
407
- account_id: @account_id,
408
- campaign_id: campaign['id'],
409
- variation_id: variation['id'],
410
- end_point: EVENTS::TRACK_USER
411
- )
393
+ 'IMPRESSION_SUCCESS',
394
+ {
395
+ '{file}' => FILE,
396
+ '{mainKeys}' => JSON.generate({'campaignId' => campaign['id'], 'variationId' => variation['id']}),
397
+ '{accountId}' => @account_id,
398
+ '{endPoint}' => EVENTS::TRACK_USER
399
+ }
412
400
  )
413
401
  end
414
402
  end
415
403
  else
416
404
  @logger.log(
417
405
  LogLevelEnum::INFO,
418
- format(
419
- LogMessageEnum::InfoMessages::USER_ALREADY_TRACKED,
420
- file: FILE,
421
- user_id: user_id,
422
- campaign_key: campaign_key,
423
- api_name: ApiMethods::ACTIVATE
424
- )
406
+ 'CAMPAIGN_USER_ALREADY_TRACKED',
407
+ {
408
+ '{file}' => FILE,
409
+ '{userId}' => user_id,
410
+ '{campaignKey}' => campaign_key,
411
+ '{api}' => ApiMethods::ACTIVATE
412
+ }
425
413
  )
426
414
  end
427
415
  variation['name']
428
416
  rescue StandardError => e
429
417
  @logger.log(
430
418
  LogLevelEnum::ERROR,
431
- format(
432
- LogMessageEnum::ErrorMessages::API_NOT_WORKING,
433
- file: FILE,
434
- api_name: ApiMethods::ACTIVATE,
435
- exception: e
436
- )
419
+ '({file}): {api} API error: ' + e.message,
420
+ {
421
+ '{file}' => FILE,
422
+ '{api}' => ApiMethods::ACTIVATE
423
+ }
437
424
  )
438
425
  e
439
426
  end
@@ -456,6 +443,7 @@ class VWO
456
443
  # Otherwise null in case of user not becoming part
457
444
  #
458
445
  def get_variation_name(campaign_key, user_id, options = {})
446
+ @logger.set_api_name(ApiMethods::GET_VARIATION_NAME)
459
447
  if is_opted_out(ApiMethods::GET_VARIATION_NAME)
460
448
  return nil
461
449
  end
@@ -463,11 +451,11 @@ class VWO
463
451
  unless @is_instance_valid
464
452
  @logger.log(
465
453
  LogLevelEnum::ERROR,
466
- format(
467
- LogMessageEnum::ErrorMessages::API_CONFIG_CORRUPTED,
468
- file: FILE,
469
- api_name: ApiMethods::GET_VARIATION_NAME
470
- )
454
+ 'CONFIG_CORRUPTED',
455
+ {
456
+ '{file}' => FILE,
457
+ '{api}' => ApiMethods::GET_VARIATION_NAME
458
+ }
471
459
  )
472
460
  return
473
461
  end
@@ -481,11 +469,11 @@ class VWO
481
469
  (variation_targeting_variables.nil? || valid_hash?(variation_targeting_variables))
482
470
  @logger.log(
483
471
  LogLevelEnum::ERROR,
484
- format(
485
- LogMessageEnum::ErrorMessages::GET_VARIATION_NAME_API_INVALID_PARAMS,
486
- api_name: ApiMethods::GET_VARIATION_NAME,
487
- file: FILE
488
- )
472
+ 'API_BAD_PARAMETERS',
473
+ {
474
+ '{file}' => FILE,
475
+ '{api}' => ApiMethods::GET_VARIATION_NAME
476
+ }
489
477
  )
490
478
  return
491
479
  end
@@ -496,13 +484,13 @@ class VWO
496
484
  # Validate campaign
497
485
  if campaign.nil? || campaign['status'] != STATUS_RUNNING
498
486
  @logger.log(
499
- LogLevelEnum::ERROR,
500
- format(
501
- LogMessageEnum::ErrorMessages::CAMPAIGN_NOT_RUNNING,
502
- file: FILE,
503
- campaign_key: campaign_key,
504
- api_name: ApiMethods::GET_VARIATION_NAME
505
- )
487
+ LogLevelEnum::WARNING,
488
+ 'CAMPAIGN_NOT_RUNNING',
489
+ {
490
+ '{file}' => FILE,
491
+ '{campaignKey}' => campaign_key,
492
+ '{api}' => ApiMethods::GET_VARIATION_NAME
493
+ }
506
494
  )
507
495
  return
508
496
  end
@@ -512,14 +500,14 @@ class VWO
512
500
  if campaign_type == CampaignTypes::FEATURE_ROLLOUT
513
501
  @logger.log(
514
502
  LogLevelEnum::ERROR,
515
- format(
516
- LogMessageEnum::ErrorMessages.INVALID_API,
517
- file: FILE,
518
- api_name: ApiMethods::GET_VARIATION_NAME,
519
- user_id: user_id,
520
- campaign_key: campaign_key,
521
- campaign_type: campaign_type
522
- )
503
+ 'API_NOT_APPLICABLE',
504
+ {
505
+ '{file}' => FILE,
506
+ '{api}' => ApiMethods::GET_VARIATION_NAME,
507
+ '{userId}' => user_id,
508
+ '{campaignKey}' => campaign_key,
509
+ '{campaignType}' => campaign_type,
510
+ }
523
511
  )
524
512
  return
525
513
  end
@@ -528,16 +516,6 @@ class VWO
528
516
 
529
517
  # Check if variation_name has been assigned
530
518
  unless valid_value?(variation)
531
- # log invalid variation key
532
- @logger.log(
533
- LogLevelEnum::INFO,
534
- format(
535
- LogMessageEnum::InfoMessages::INVALID_VARIATION_KEY,
536
- file: FILE,
537
- user_id: user_id,
538
- campaign_key: campaign_key
539
- )
540
- )
541
519
  return
542
520
  end
543
521
 
@@ -545,12 +523,11 @@ class VWO
545
523
  rescue StandardError => e
546
524
  @logger.log(
547
525
  LogLevelEnum::ERROR,
548
- format(
549
- LogMessageEnum::ErrorMessages::API_NOT_WORKING,
550
- file: FILE,
551
- api_name: ApiMethods::GET_VARIATION_NAME,
552
- exception: e
553
- )
526
+ '({file}): {api} API error: ' + e.message,
527
+ {
528
+ '{file}' => FILE,
529
+ '{api}' => ApiMethods::GET_VARIATION_NAME
530
+ }
554
531
  )
555
532
  nil
556
533
  end
@@ -571,6 +548,7 @@ class VWO
571
548
  #
572
549
 
573
550
  def track(campaign_key, user_id, goal_identifier, options = {})
551
+ @logger.set_api_name(ApiMethods::TRACK)
574
552
  if is_opted_out(ApiMethods::TRACK)
575
553
  return false
576
554
  end
@@ -578,11 +556,11 @@ class VWO
578
556
  unless @is_instance_valid
579
557
  @logger.log(
580
558
  LogLevelEnum::ERROR,
581
- format(
582
- LogMessageEnum::ErrorMessages::API_CONFIG_CORRUPTED,
583
- file: FILE,
584
- api_name: ApiMethods::TRACK
585
- )
559
+ 'CONFIG_CORRUPTED',
560
+ {
561
+ '{file}' => FILE,
562
+ '{api}' => ApiMethods::TRACK
563
+ }
586
564
  )
587
565
  return false
588
566
  end
@@ -599,11 +577,11 @@ class VWO
599
577
  # log invalid params
600
578
  @logger.log(
601
579
  LogLevelEnum::ERROR,
602
- format(
603
- LogMessageEnum::ErrorMessages::TRACK_API_INVALID_PARAMS,
604
- file: FILE,
605
- api_name: ApiMethods::TRACK
606
- )
580
+ 'API_BAD_PARAMETERS',
581
+ {
582
+ '{file}' => FILE,
583
+ '{api}' => ApiMethods::TRACK
584
+ }
607
585
  )
608
586
  return false
609
587
  end
@@ -619,6 +597,7 @@ class VWO
619
597
  metric_map = {}
620
598
  revenue_props = []
621
599
  result = {}
600
+ batch_event_data = {"ev" => []}
622
601
  campaigns.each do |campaign|
623
602
  begin
624
603
  campaign_type = campaign['type']
@@ -626,14 +605,14 @@ class VWO
626
605
  if campaign_type == CampaignTypes::FEATURE_ROLLOUT
627
606
  @logger.log(
628
607
  LogLevelEnum::ERROR,
629
- format(
630
- LogMessageEnum::ErrorMessages::INVALID_API,
631
- file: FILE,
632
- api_name: ApiMethods::TRACK,
633
- user_id: user_id,
634
- campaign_key: campaign['key'],
635
- campaign_type: campaign_type
636
- )
608
+ 'API_NOT_APPLICABLE',
609
+ {
610
+ '{file}' => FILE,
611
+ '{api}' => ApiMethods::TRACK,
612
+ '{userId}' => user_id,
613
+ '{campaignKey}' => campaign_key,
614
+ '{campaignType}' => campaign_type,
615
+ }
637
616
  )
638
617
  result[campaign['key']] = false
639
618
  next
@@ -646,28 +625,26 @@ class VWO
646
625
  if goal.nil? || !goal["id"]
647
626
  @logger.log(
648
627
  LogLevelEnum::ERROR,
649
- format(
650
- LogMessageEnum::ErrorMessages::TRACK_API_GOAL_NOT_FOUND,
651
- file: FILE,
652
- goal_identifier: goal_identifier,
653
- user_id: user_id,
654
- campaign_key: campaign['key'],
655
- api_name: ApiMethods::TRACK
656
- )
628
+ 'TRACK_API_GOAL_NOT_FOUND',
629
+ {
630
+ '{file}' => FILE,
631
+ '{goalIdentifier}' => goal_identifier,
632
+ '{userId}' => user_id,
633
+ '{campaignKey}' => campaign['key']
634
+ }
657
635
  )
658
636
  result[campaign['key']] = false
659
637
  next
660
638
  elsif goal['type'] == GoalTypes::REVENUE && !valid_value?(revenue_value)
661
639
  @logger.log(
662
640
  LogLevelEnum::ERROR,
663
- format(
664
- LogMessageEnum::ErrorMessages::TRACK_API_REVENUE_NOT_PASSED_FOR_REVENUE_GOAL,
665
- file: FILE,
666
- user_id: user_id,
667
- goal_identifier: goal_identifier,
668
- campaign_key: campaign['key'],
669
- api_name: ApiMethods::TRACK
670
- )
641
+ 'TRACK_API_REVENUE_NOT_PASSED_FOR_REVENUE_GOAL',
642
+ {
643
+ '{file}' => FILE,
644
+ '{userId}' => user_id,
645
+ '{goalIdentifier}' => goal_identifier,
646
+ '{campaignKey}' => campaign['key']
647
+ }
671
648
  )
672
649
  result[campaign['key']] = false
673
650
  next
@@ -690,14 +667,13 @@ class VWO
690
667
  else
691
668
  @logger.log(
692
669
  LogLevelEnum::INFO,
693
- format(
694
- LogMessageEnum::InfoMessages::GOAL_ALREADY_TRACKED,
695
- file: FILE,
696
- user_id: user_id,
697
- campaign_key: campaign['key'],
698
- goal_identifier: goal_identifier,
699
- api_name: ApiMethods::TRACK
700
- )
670
+ 'CAMPAIGN_GOAL_ALREADY_TRACKED',
671
+ {
672
+ '{file}' => FILE,
673
+ '{userId}' => user_id,
674
+ '{campaignKey}' => campaign['key'],
675
+ '{goalIdentifier}' => goal_identifier
676
+ }
701
677
  )
702
678
  result[campaign['key']] = false
703
679
  next
@@ -718,7 +694,7 @@ class VWO
718
694
  if goal['type'] == GoalTypes::REVENUE && !(revenue_props.include? goal['revenueProp'])
719
695
  revenue_props << goal['revenueProp']
720
696
  end
721
- else
697
+ elsif campaigns.count == 1
722
698
  impression = create_impression(
723
699
  @settings_file,
724
700
  campaign['id'],
@@ -731,26 +707,24 @@ class VWO
731
707
  if @event_dispatcher.dispatch(impression)
732
708
  @logger.log(
733
709
  LogLevelEnum::INFO,
734
- format(
735
- LogMessageEnum::InfoMessages::IMPRESSION_SUCCESS,
736
- file: FILE,
737
- account_id: @account_id,
738
- campaign_id: campaign['id'],
739
- variation_id: variation['id'],
740
- end_point: EVENTS::TRACK_GOAL
741
- )
742
- )
743
- @logger.log(
744
- LogLevelEnum::INFO,
745
- format(
746
- LogMessageEnum::InfoMessages::MAIN_KEYS_FOR_IMPRESSION,
747
- file: FILE,
748
- campaign_id: impression[:experiment_id],
749
- account_id: impression[:account_id],
750
- variation_id: impression[:combination]
751
- )
710
+ 'IMPRESSION_SUCCESS',
711
+ {
712
+ '{file}' => FILE,
713
+ '{mainKeys}' => JSON.generate({'campaignId' => campaign['id'], 'variationId' => variation['id'], 'goalId' => goal['id']}),
714
+ '{accountId}' => @account_id,
715
+ '{endPoint}' => EVENTS::TRACK_GOAL
716
+ }
752
717
  )
753
718
  end
719
+ else
720
+ batch_event_data["ev"] << create_bulk_event_impression(
721
+ @settings_file,
722
+ campaign['id'],
723
+ variation['id'],
724
+ user_id,
725
+ goal['id'],
726
+ revenue_value
727
+ )
754
728
  end
755
729
  result[campaign['key']] = true
756
730
  next
@@ -759,22 +733,27 @@ class VWO
759
733
  rescue StandardError => e
760
734
  @logger.log(
761
735
  LogLevelEnum::ERROR,
762
- format(
763
- e.message,
764
- file: FILE,
765
- exception: e
766
- )
736
+ '({file}): {api} API error: ' + e.message,
737
+ {
738
+ '{file}' => FILE,
739
+ '{api}' => ApiMethods::TRACK
740
+ }
767
741
  )
768
742
  end
769
743
  end
770
744
 
745
+ multiple_call_response = false # use for normal call when track multiple goals in single call
771
746
  if is_event_arch_enabled
772
747
  properties = get_events_base_properties(@settings_file, goal_identifier)
773
748
  payload = get_track_goal_payload_data(@settings_file, user_id, goal_identifier, revenue_value, metric_map, revenue_props)
774
749
  @event_dispatcher.dispatch_event_arch_post(properties, payload)
750
+ elsif batch_event_data["ev"].count != 0
751
+ paramters = get_batch_event_query_params(@settings_file['accountId'], @sdk_key, @usage_stats.usage_stats)
752
+ batch_events_dispatcher = VWO::Services::BatchEventsDispatcher.new(@is_development_mode)
753
+ multiple_call_response = batch_events_dispatcher.dispatch(batch_event_data, nil, paramters)
775
754
  end
776
755
 
777
- if result.length() == 0
756
+ if result.length() == 0 || (batch_event_data["ev"].count != 0 && !multiple_call_response)
778
757
  return nil
779
758
  end
780
759
 
@@ -782,12 +761,11 @@ class VWO
782
761
  rescue StandardError => e
783
762
  @logger.log(
784
763
  LogLevelEnum::ERROR,
785
- format(
786
- LogMessageEnum::ErrorMessages::API_NOT_WORKING,
787
- file: FILE,
788
- api_name: ApiMethods::TRACK,
789
- exception: e
790
- )
764
+ '({file}): {api} API error: ' + e.message,
765
+ {
766
+ '{file}' => FILE,
767
+ '{api}' => ApiMethods::TRACK
768
+ }
791
769
  )
792
770
  false
793
771
  end
@@ -806,6 +784,7 @@ class VWO
806
784
  # @return[Boolean] true if user becomes part of feature test/rollout, otherwise false.
807
785
 
808
786
  def feature_enabled?(campaign_key, user_id, options = {})
787
+ @logger.set_api_name(ApiMethods::IS_FEATURE_ENABLED)
809
788
  if is_opted_out(ApiMethods::IS_FEATURE_ENABLED)
810
789
  return false
811
790
  end
@@ -813,11 +792,11 @@ class VWO
813
792
  unless @is_instance_valid
814
793
  @logger.log(
815
794
  LogLevelEnum::ERROR,
816
- format(
817
- LogMessageEnum::ErrorMessages::API_CONFIG_CORRUPTED,
818
- file: FILE,
819
- api_name: ApiMethods::IS_FEATURE_ENABLED
820
- )
795
+ 'CONFIG_CORRUPTED',
796
+ {
797
+ '{file}' => FILE,
798
+ '{api}' => ApiMethods::IS_FEATURE_ENABLED
799
+ }
821
800
  )
822
801
  return false
823
802
  end
@@ -826,25 +805,17 @@ class VWO
826
805
  # Retrieve custom variables
827
806
  custom_variables = options[:custom_variables]
828
807
  variation_targeting_variables = options[:variation_targeting_variables]
829
- @logger.log(
830
- LogLevelEnum::INFO,
831
- format(
832
- LogMessageEnum::InfoMessages::API_CALLED,
833
- file: FILE,
834
- api_name: ApiMethods::IS_FEATURE_ENABLED,
835
- user_id: user_id
836
- )
837
- )
808
+
838
809
  # Validate input parameters
839
810
  unless valid_string?(campaign_key) && valid_string?(user_id) && (custom_variables.nil? || valid_hash?(custom_variables)) &&
840
811
  (variation_targeting_variables.nil? || valid_hash?(variation_targeting_variables))
841
812
  @logger.log(
842
813
  LogLevelEnum::ERROR,
843
- format(
844
- LogMessageEnum::ErrorMessages::IS_FEATURE_ENABLED_API_INVALID_PARAMS,
845
- api_name: ApiMethods::IS_FEATURE_ENABLED,
846
- file: FILE
847
- )
814
+ 'API_BAD_PARAMETERS',
815
+ {
816
+ '{file}' => FILE,
817
+ '{api}' => ApiMethods::IS_FEATURE_ENABLED
818
+ }
848
819
  )
849
820
  return false
850
821
  end
@@ -856,13 +827,13 @@ class VWO
856
827
  unless campaign && campaign['status'] == STATUS_RUNNING
857
828
  # log error
858
829
  @logger.log(
859
- LogLevelEnum::ERROR,
860
- format(
861
- LogMessageEnum::ErrorMessages::CAMPAIGN_NOT_RUNNING,
862
- file: FILE,
863
- campaign_key: campaign_key,
864
- api_name: ApiMethods::IS_FEATURE_ENABLED
865
- )
830
+ LogLevelEnum::WARNING,
831
+ 'CAMPAIGN_NOT_RUNNING',
832
+ {
833
+ '{file}' => FILE,
834
+ '{campaignKey}' => campaign_key,
835
+ '{api}' => ApiMethods::IS_FEATURE_ENABLED
836
+ }
866
837
  )
867
838
  return false
868
839
  end
@@ -873,14 +844,14 @@ class VWO
873
844
  if campaign_type == CampaignTypes::VISUAL_AB
874
845
  @logger.log(
875
846
  LogLevelEnum::ERROR,
876
- format(
877
- LogMessageEnum::ErrorMessages::INVALID_API,
878
- file: FILE,
879
- api_name: ApiMethods::IS_FEATURE_ENABLED,
880
- user_id: user_id,
881
- campaign_key: campaign_key,
882
- campaign_type: campaign_type
883
- )
847
+ 'API_NOT_APPLICABLE',
848
+ {
849
+ '{file}' => FILE,
850
+ '{api}' => ApiMethods::IS_FEATURE_ENABLED,
851
+ '{userId}' => user_id,
852
+ '{campaignKey}' => campaign_key,
853
+ '{campaignType}' => campaign_type,
854
+ }
884
855
  )
885
856
  return false
886
857
  end
@@ -920,27 +891,27 @@ class VWO
920
891
 
921
892
  @event_dispatcher.dispatch(impression)
922
893
  @logger.log(
923
- LogLevelEnum::INFO,
924
- format(
925
- LogMessageEnum::InfoMessages::MAIN_KEYS_FOR_IMPRESSION,
926
- file: FILE,
927
- campaign_id: impression[:experiment_id],
928
- account_id: impression[:account_id],
929
- variation_id: impression[:combination]
894
+ LogLevelEnum::INFO,
895
+ 'IMPRESSION_SUCCESS',
896
+ {
897
+ '{file}' => FILE,
898
+ '{mainKeys}' => JSON.generate({'campaignId' => impression[:experiment_id]}),
899
+ '{accountId}' => @account_id,
900
+ '{endPoint}' => EVENTS::TRACK_USER
901
+ }
930
902
  )
931
- )
932
903
  end
933
904
 
934
905
  else
935
906
  @logger.log(
936
907
  LogLevelEnum::INFO,
937
- format(
938
- LogMessageEnum::InfoMessages::USER_ALREADY_TRACKED,
939
- file: FILE,
940
- user_id: user_id,
941
- campaign_key: campaign_key,
942
- api_name: ApiMethods::IS_FEATURE_ENABLED
943
- )
908
+ 'CAMPAIGN_USER_ALREADY_TRACKED',
909
+ {
910
+ '{file}' => FILE,
911
+ '{userId}' => user_id,
912
+ '{campaignKey}' => campaign_key,
913
+ '{api}' => ApiMethods::IS_FEATURE_ENABLED
914
+ }
944
915
  )
945
916
  end
946
917
  if campaign_type == CampaignTypes::FEATURE_ROLLOUT
@@ -952,24 +923,24 @@ class VWO
952
923
  if result
953
924
  @logger.log(
954
925
  LogLevelEnum::INFO,
955
- format(
956
- LogMessageEnum::InfoMessages::FEATURE_ENABLED_FOR_USER,
957
- file: FILE,
958
- user_id: user_id,
959
- feature_key: campaign_key,
960
- api_name: ApiMethods::IS_FEATURE_ENABLED
961
- )
926
+ 'FEATURE_STATUS',
927
+ {
928
+ '{file}' => FILE,
929
+ '{userId}' => user_id,
930
+ '{campaignKey}' => campaign_key,
931
+ '{status}' => 'enabled'
932
+ }
962
933
  )
963
934
  else
964
935
  @logger.log(
965
936
  LogLevelEnum::INFO,
966
- format(
967
- LogMessageEnum::InfoMessages::FEATURE_NOT_ENABLED_FOR_USER,
968
- file: FILE,
969
- user_id: user_id,
970
- feature_key: campaign_key,
971
- api_name: ApiMethods::IS_FEATURE_ENABLED
972
- )
937
+ 'FEATURE_STATUS',
938
+ {
939
+ '{file}' => FILE,
940
+ '{userId}' => user_id,
941
+ '{campaignKey}' => campaign_key,
942
+ '{status}' => 'disabled'
943
+ }
973
944
  )
974
945
  end
975
946
 
@@ -977,12 +948,11 @@ class VWO
977
948
  rescue StandardError => e
978
949
  @logger.log(
979
950
  LogLevelEnum::ERROR,
980
- format(
981
- LogMessageEnum::ErrorMessages::API_NOT_WORKING,
982
- file: FILE,
983
- api_name: ApiMethods::IS_FEATURE_ENABLED,
984
- exception: e
985
- )
951
+ '({file}): {api} API error: ' + e.message,
952
+ {
953
+ '{file}' => FILE,
954
+ '{api}' => ApiMethods::IS_FEATURE_ENABLED
955
+ }
986
956
  )
987
957
  false
988
958
  end
@@ -1007,6 +977,7 @@ class VWO
1007
977
  #
1008
978
 
1009
979
  def get_feature_variable_value(campaign_key, variable_key, user_id, options = {})
980
+ @logger.set_api_name(ApiMethods::GET_FEATURE_VARIABLE_VALUE)
1010
981
  if is_opted_out(ApiMethods::GET_FEATURE_VARIABLE_VALUE)
1011
982
  return nil
1012
983
  end
@@ -1014,11 +985,11 @@ class VWO
1014
985
  unless @is_instance_valid
1015
986
  @logger.log(
1016
987
  LogLevelEnum::ERROR,
1017
- format(
1018
- LogMessageEnum::ErrorMessages::API_CONFIG_CORRUPTED,
1019
- file: FILE,
1020
- api_name: ApiMethods::GET_FEATURE_VARIABLE_VALUE
1021
- )
988
+ 'CONFIG_CORRUPTED',
989
+ {
990
+ '{file}' => FILE,
991
+ '{api}' => ApiMethods::GET_FEATURE_VARIABLE_VALUE
992
+ }
1022
993
  )
1023
994
  return
1024
995
  end
@@ -1032,11 +1003,11 @@ class VWO
1032
1003
  (custom_variables.nil? || valid_hash?(custom_variables)) && (variation_targeting_variables.nil? || valid_hash?(variation_targeting_variables))
1033
1004
  @logger.log(
1034
1005
  LogLevelEnum::ERROR,
1035
- format(
1036
- LogMessageEnum::ErrorMessages::GET_FEATURE_VARIABLE_VALUE_API_INVALID_PARAMS,
1037
- file: FILE,
1038
- api_name: ApiMethods::GET_FEATURE_VARIABLE_VALUE
1039
- )
1006
+ 'API_BAD_PARAMETERS',
1007
+ {
1008
+ '{file}' => FILE,
1009
+ '{api}' => ApiMethods::GET_FEATURE_VARIABLE_VALUE
1010
+ }
1040
1011
  )
1041
1012
  return
1042
1013
  end
@@ -1048,13 +1019,13 @@ class VWO
1048
1019
  unless campaign && campaign['status'] == STATUS_RUNNING
1049
1020
  # log error
1050
1021
  @logger.log(
1051
- LogLevelEnum::ERROR,
1052
- format(
1053
- LogMessageEnum::ErrorMessages::CAMPAIGN_NOT_RUNNING,
1054
- file: FILE,
1055
- campaign_key: campaign_key,
1056
- api_name: ApiMethods::GET_FEATURE_VARIABLE_VALUE
1057
- )
1022
+ LogLevelEnum::WARNING,
1023
+ 'CAMPAIGN_NOT_RUNNING',
1024
+ {
1025
+ '{file}' => FILE,
1026
+ '{campaignKey}' => campaign_key,
1027
+ '{api}' => ApiMethods::GET_FEATURE_VARIABLE_VALUE
1028
+ }
1058
1029
  )
1059
1030
  return
1060
1031
  end
@@ -1064,14 +1035,14 @@ class VWO
1064
1035
  if campaign_type == CampaignTypes::VISUAL_AB
1065
1036
  @logger.log(
1066
1037
  LogLevelEnum::ERROR,
1067
- format(
1068
- LogMessageEnum::ErrorMessages::INVALID_API,
1069
- file: FILE,
1070
- api_name: ApiMethods::GET_FEATURE_VARIABLE_VALUE,
1071
- campaign_key: campaign_key,
1072
- campaign_type: campaign_type,
1073
- user_id: user_id
1074
- )
1038
+ 'API_NOT_APPLICABLE',
1039
+ {
1040
+ '{file}' => FILE,
1041
+ '{api}' => ApiMethods::GET_FEATURE_VARIABLE_VALUE,
1042
+ '{userId}' => user_id,
1043
+ '{campaignKey}' => campaign_key,
1044
+ '{campaignType}' => campaign_type,
1045
+ }
1075
1046
  )
1076
1047
  return
1077
1048
  end
@@ -1086,27 +1057,27 @@ class VWO
1086
1057
  elsif campaign_type == CampaignTypes::FEATURE_TEST
1087
1058
  if !variation['isFeatureEnabled']
1088
1059
  @logger.log(
1089
- LogLevelEnum::INFO,
1090
- format(
1091
- LogMessageEnum::InfoMessages::FEATURE_NOT_ENABLED_FOR_USER,
1092
- file: FILE,
1093
- feature_key: campaign_key,
1094
- user_id: user_id,
1095
- api_name: ApiMethods::GET_FEATURE_VARIABLE_VALUE
1096
- )
1097
- )
1060
+ LogLevelEnum::INFO,
1061
+ 'FEATURE_STATUS',
1062
+ {
1063
+ '{file}' => FILE,
1064
+ '{userId}' => user_id,
1065
+ '{campaignKey}' => campaign_key,
1066
+ '{status}' => 'disabled'
1067
+ }
1068
+ )
1098
1069
  variation = get_control_variation(campaign)
1099
1070
  else
1100
1071
  @logger.log(
1101
- LogLevelEnum::INFO,
1102
- format(
1103
- LogMessageEnum::InfoMessages::FEATURE_ENABLED_FOR_USER,
1104
- file: FILE,
1105
- feature_key: campaign_key,
1106
- user_id: user_id,
1107
- api_name: ApiMethods::GET_FEATURE_VARIABLE_VALUE
1108
- )
1109
- )
1072
+ LogLevelEnum::INFO,
1073
+ 'FEATURE_STATUS',
1074
+ {
1075
+ '{file}' => FILE,
1076
+ '{userId}' => user_id,
1077
+ '{campaignKey}' => campaign_key,
1078
+ '{status}' => 'enabled'
1079
+ }
1080
+ )
1110
1081
  end
1111
1082
  variables = variation['variables']
1112
1083
  end
@@ -1115,43 +1086,37 @@ class VWO
1115
1086
  unless variable
1116
1087
  # Log variable not found
1117
1088
  @logger.log(
1118
- LogLevelEnum::ERROR,
1119
- format(
1120
- LogMessageEnum::ErrorMessages::VARIABLE_NOT_FOUND,
1121
- file: FILE,
1122
- variable_key: variable_key,
1123
- campaign_key: campaign_key,
1124
- campaign_type: campaign_type,
1125
- user_id: user_id,
1126
- api_name: ApiMethods::GET_FEATURE_VARIABLE_VALUE
1127
- )
1089
+ LogLevelEnum::INFO,
1090
+ 'FEATURE_VARIABLE_DEFAULT_VALUE',
1091
+ {
1092
+ '{file}' => FILE,
1093
+ '{variableKey}' => variable_key,
1094
+ '{variationName}' => variation['name']
1095
+ }
1128
1096
  )
1129
1097
  return
1130
1098
  end
1131
1099
 
1132
1100
  @logger.log(
1133
1101
  LogLevelEnum::INFO,
1134
- format(
1135
- LogMessageEnum::InfoMessages::VARIABLE_FOUND,
1136
- file: FILE,
1137
- variable_key: variable_key,
1138
- variable_value: variable['value'],
1139
- campaign_key: campaign_key,
1140
- campaign_type: campaign_type,
1141
- user_id: user_id,
1142
- api_name: ApiMethods::GET_FEATURE_VARIABLE_VALUE
1143
- )
1102
+ 'FEATURE_VARIABLE_VALUE',
1103
+ {
1104
+ '{file}' => FILE,
1105
+ '{variableKey}' => variable_key,
1106
+ '{variableValue}' => variable['value'],
1107
+ '{campaignKey}' => campaign_key,
1108
+ '{userId}' => user_id,
1109
+ }
1144
1110
  )
1145
1111
  get_type_casted_feature_value(variable['value'], variable['type'])
1146
1112
  rescue StandardError => e
1147
1113
  @logger.log(
1148
1114
  LogLevelEnum::ERROR,
1149
- format(
1150
- LogMessageEnum::ErrorMessages::API_NOT_WORKING,
1151
- file: FILE,
1152
- api_name: ApiMethods::GET_FEATURE_VARIABLE_VALUE,
1153
- exception: e
1154
- )
1115
+ '({file}): {api} API error: ' + e.message,
1116
+ {
1117
+ '{file}' => FILE,
1118
+ '{api}' => ApiMethods::GET_FEATURE_VARIABLE_VALUE
1119
+ }
1155
1120
  )
1156
1121
  nil
1157
1122
  end
@@ -1165,20 +1130,21 @@ class VWO
1165
1130
  # @return true if call is made successfully, else false
1166
1131
 
1167
1132
  def push(tag_key, tag_value, user_id = nil)
1133
+ @logger.set_api_name(ApiMethods::PUSH)
1168
1134
  if is_opted_out(ApiMethods::PUSH)
1169
- return false
1135
+ return {}
1170
1136
  end
1171
1137
 
1172
1138
  unless @is_instance_valid
1173
1139
  @logger.log(
1174
1140
  LogLevelEnum::ERROR,
1175
- format(
1176
- LogMessageEnum::ErrorMessages::API_CONFIG_CORRUPTED,
1177
- file: FILE,
1178
- api_name: ApiMethods::PUSH
1179
- )
1141
+ 'CONFIG_CORRUPTED',
1142
+ {
1143
+ '{file}' => FILE,
1144
+ '{api}' => ApiMethods::PUSH
1145
+ }
1180
1146
  )
1181
- return false
1147
+ return {}
1182
1148
  end
1183
1149
 
1184
1150
  # Argument reshuffling.
@@ -1190,84 +1156,111 @@ class VWO
1190
1156
  custom_dimension_map[tag_key.to_sym] = tag_value
1191
1157
  end
1192
1158
 
1193
- unless (valid_string?(tag_key) || valid_hash?(tag_key)) && valid_string?(tag_value) && valid_string?(user_id)
1159
+ unless (valid_string?(tag_key) || valid_hash?(tag_key)) && valid_string?(user_id)
1194
1160
  @logger.log(
1195
1161
  LogLevelEnum::ERROR,
1196
- format(
1197
- LogMessageEnum::ErrorMessages::PUSH_API_INVALID_PARAMS,
1198
- file: FILE,
1199
- api_name: ApiMethods::PUSH
1200
- )
1162
+ 'API_BAD_PARAMETERS',
1163
+ {
1164
+ '{file}' => FILE,
1165
+ '{api}' => ApiMethods::PUSH
1166
+ }
1201
1167
  )
1202
- return false
1168
+ return {}
1203
1169
  end
1204
1170
 
1171
+ result = {}
1205
1172
  custom_dimension_map.each do |tag_key, tag_value|
1206
- if tag_key.length > PushApi::TAG_KEY_LENGTH
1173
+ if !tag_key.is_a?(Symbol) || !tag_value.is_a?(String)
1174
+ custom_dimension_map.delete(tag_key)
1175
+ result[tag_key] = false
1176
+ next
1177
+ end
1178
+
1179
+ if tag_key.length > PushApi::TAG_KEY_LENGTH || tag_key.length == 0
1207
1180
  @logger.log(
1208
1181
  LogLevelEnum::ERROR,
1209
- format(
1210
- LogMessageEnum::ErrorMessages::TAG_KEY_LENGTH_EXCEEDED,
1211
- file: FILE,
1212
- user_id: user_id,
1213
- tag_key: tag_key,
1214
- api_name: ApiMethods::PUSH
1215
- )
1182
+ 'TAG_KEY_LENGTH_EXCEEDED',
1183
+ {
1184
+ '{file}' => FILE,
1185
+ '{userId}' => user_id,
1186
+ '{tagKey}' => tag_key
1187
+ }
1216
1188
  )
1217
- return false
1189
+ custom_dimension_map.delete(tag_key)
1190
+ result[tag_key] = false
1191
+ next
1218
1192
  end
1219
1193
 
1220
- if tag_value.length > PushApi::TAG_VALUE_LENGTH
1194
+ if tag_value.length > PushApi::TAG_VALUE_LENGTH || tag_value.length == 0
1221
1195
  @logger.log(
1222
1196
  LogLevelEnum::ERROR,
1223
- format(
1224
- LogMessageEnum::ErrorMessages::TAG_VALUE_LENGTH_EXCEEDED,
1225
- file: FILE,
1226
- user_id: user_id,
1227
- tag_value: tag_value,
1228
- api_name: ApiMethods::PUSH
1229
- )
1197
+ 'TAG_VALUE_LENGTH_EXCEEDED',
1198
+ {
1199
+ '{file}' => FILE,
1200
+ '{userId}' => user_id,
1201
+ '{tagKey}' => tag_key,
1202
+ '{tagValue}' => tag_value
1203
+ }
1230
1204
  )
1231
- return false
1205
+ custom_dimension_map.delete(tag_key)
1206
+ result[tag_key] = false
1232
1207
  end
1233
1208
  end
1234
1209
 
1210
+ if custom_dimension_map.count == 0
1211
+ @logger.log(
1212
+ LogLevelEnum::ERROR,
1213
+ 'API_BAD_PARAMETERS',
1214
+ {
1215
+ '{file}' => FILE,
1216
+ '{api}' => ApiMethods::PUSH
1217
+ }
1218
+ )
1219
+ return result
1220
+ end
1221
+
1235
1222
  if defined?(@batch_events)
1236
1223
  custom_dimension_map.each do |tag_key, tag_value|
1237
1224
  impression = get_batch_event_url_params(@settings_file, tag_key, tag_value, user_id)
1238
1225
  @batch_events_queue.enqueue(impression)
1239
1226
  end
1227
+ resp = true
1240
1228
  elsif is_event_arch_enabled
1241
1229
  properties = get_events_base_properties(@settings_file, EventEnum::VWO_SYNC_VISITOR_PROP)
1242
1230
  payload = get_push_payload_data(@settings_file, user_id, EventEnum::VWO_SYNC_VISITOR_PROP, custom_dimension_map)
1243
- @event_dispatcher.dispatch_event_arch_post(properties, payload)
1244
- else
1231
+ resp = @event_dispatcher.dispatch_event_arch_post(properties, payload)
1232
+ elsif custom_dimension_map.count == 1
1245
1233
  custom_dimension_map.each do |tag_key, tag_value|
1246
1234
  impression = get_url_params(@settings_file, tag_key, tag_value, user_id, @sdk_key)
1247
- @event_dispatcher.dispatch(impression)
1248
-
1235
+ result[tag_key] = @event_dispatcher.dispatch(impression)
1249
1236
  @logger.log(
1250
1237
  LogLevelEnum::INFO,
1251
- format(
1252
- LogMessageEnum::InfoMessages::MAIN_KEYS_FOR_PUSH_API,
1253
- file: FILE,
1254
- u: impression['u'],
1255
- account_id: impression['account_id'],
1256
- tags: impression['tags']
1257
- )
1238
+ 'IMPRESSION_SUCCESS',
1239
+ {
1240
+ '{file}' => FILE,
1241
+ '{endPoint}' => ApiMethods::PUSH,
1242
+ '{accountId}' => @settings_file['accountId'],
1243
+ '{mainKeys}' => JSON.generate({'tags' => impression['tags']}),
1244
+ }
1258
1245
  )
1259
1246
  end
1247
+ resp = true
1248
+ else
1249
+ batch_event_data = {"ev" => []}
1250
+ custom_dimension_map.each do |tag_key, tag_value|
1251
+ batch_event_data["ev"] << get_batch_event_url_params(@settings_file, tag_key, tag_value, user_id)
1252
+ end
1253
+ paramters = get_batch_event_query_params(@settings_file['accountId'], @sdk_key, @usage_stats.usage_stats)
1254
+ batch_events_dispatcher = VWO::Services::BatchEventsDispatcher.new(@is_development_mode)
1255
+ resp = batch_events_dispatcher.dispatch(batch_event_data, nil, paramters)
1260
1256
  end
1261
- true
1257
+
1258
+ return prepare_push_response(custom_dimension_map, resp, result)
1262
1259
  rescue StandardError => e
1263
1260
  @logger.log(
1264
1261
  LogLevelEnum::ERROR,
1265
- format(
1266
- LogMessageEnum::ErrorMessages::API_NOT_WORKING,
1267
- file: FILE,
1268
- api_name: ApiMethods::PUSH,
1269
- exception: e
1270
- )
1262
+ '({file}): push API error: ' + e.message,
1263
+ {'{file}' => FILE}
1271
1264
  )
1272
1265
  false
1273
1266
  end
@@ -1276,7 +1269,10 @@ class VWO
1276
1269
  !@user_storage || !@variation_decider.has_stored_variation
1277
1270
  end
1278
1271
 
1272
+ # Manually flush impression events to VWO which are queued in batch queue as per batchEvents config
1273
+ # @return[bool]
1279
1274
  def flush_events
1275
+ @logger.set_api_name(ApiMethods::FLUSH_EVENTS)
1280
1276
  if is_opted_out(ApiMethods::FLUSH_EVENTS)
1281
1277
  return false
1282
1278
  end
@@ -1284,11 +1280,11 @@ class VWO
1284
1280
  unless @is_instance_valid
1285
1281
  @logger.log(
1286
1282
  LogLevelEnum::ERROR,
1287
- format(
1288
- LogMessageEnum::ErrorMessages::API_CONFIG_CORRUPTED,
1289
- file: FILE,
1290
- api_name: ApiMethods::FLUSH_EVENTS
1291
- )
1283
+ 'CONFIG_CORRUPTED',
1284
+ {
1285
+ '{file}' => FILE,
1286
+ '{api}' => ApiMethods::FLUSH_EVENTS
1287
+ }
1292
1288
  )
1293
1289
  return false
1294
1290
  end
@@ -1301,12 +1297,11 @@ class VWO
1301
1297
  rescue StandardError => e
1302
1298
  @logger.log(
1303
1299
  LogLevelEnum::ERROR,
1304
- format(
1305
- LogMessageEnum::ErrorMessages::API_NOT_WORKING,
1306
- file: FILE,
1307
- api_name: ApiMethods::FLUSH_EVENTS,
1308
- exception: e
1309
- )
1300
+ '({file}): {api} API error: ' + e.message,
1301
+ {
1302
+ '{file}' => FILE,
1303
+ '{api}' => ApiMethods::FLUSH_EVENTS
1304
+ }
1310
1305
  )
1311
1306
  false
1312
1307
  end
@@ -1323,12 +1318,15 @@ class VWO
1323
1318
  goal_type_to_track = options[:goal_type_to_track]
1324
1319
  else
1325
1320
  @logger.log(
1326
- LogLevelEnum::ERROR,
1327
- format(
1328
- LogMessageEnum::ErrorMessages::INVALID_GOAL_TYPE,
1329
- file: FILE
1321
+ LogLevelEnum::ERROR,
1322
+ 'CONFIG_PARAMETER_INVALID',
1323
+ {
1324
+ '{file}' => FILE,
1325
+ '{parameter}' => 'goal_type_to_track',
1326
+ '{type}' => 'string(REVENUE, CUSTOM, ALL)',
1327
+ '{api}' => 'init'
1328
+ }
1330
1329
  )
1331
- )
1332
1330
  end
1333
1331
  goal_type_to_track
1334
1332
  end
@@ -1338,12 +1336,13 @@ class VWO
1338
1336
  # return[bool]
1339
1337
  #
1340
1338
  def set_opt_out
1341
- @logger.log(
1339
+ @logger.set_api_name(ApiMethods::OPT_OUT)
1340
+ @logger.log(
1342
1341
  LogLevelEnum::INFO,
1343
- format(
1344
- LogMessageEnum::InfoMessages::OPT_OUT_API_CALLED,
1345
- file: FILE
1346
- )
1342
+ 'OPT_OUT_API_CALLED',
1343
+ {
1344
+ '{file}' => FILE
1345
+ }
1347
1346
  )
1348
1347
  if defined?(@batch_events) && !@batch_events_queue.nil?
1349
1348
  @batch_events_queue.flush(manual: true)
@@ -1372,11 +1371,11 @@ class VWO
1372
1371
  if @is_opted_out
1373
1372
  @logger.log(
1374
1373
  LogLevelEnum::INFO,
1375
- format(
1376
- LogMessageEnum::InfoMessages::API_NOT_ENABLED,
1377
- file: FILE,
1378
- api: api_name
1379
- )
1374
+ 'API_NOT_ENABLED',
1375
+ {
1376
+ '{file}' => FILE,
1377
+ '{api}' => api_name
1378
+ }
1380
1379
  )
1381
1380
  end
1382
1381
  return @is_opted_out