optimizely-sdk 3.6.0 → 3.7.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: 4d8204dce32c85bea56820607c0268b363fb86e7506ce685a2675645b4ef581b
4
- data.tar.gz: dce7cd63fde5e24e179a74f8f14c6a22ed389028faac38a373af105683b596f0
3
+ metadata.gz: 84b914d98655786586e8f691c82529bb3a8f074a6c157aceff6c2ef0ab4a4e3e
4
+ data.tar.gz: 484164de6c112f23adc94568371a33f564a99dba714c3141cf156783cb638a5d
5
5
  SHA512:
6
- metadata.gz: 5cc88f9802b38a2eb29354507303c6dcdcf6a402f721d24689f1e42a52a79319568974cf3584c6bf94398ff5f1410aacf49a1adf7aa27ef9105f3e7b23d39e3d
7
- data.tar.gz: a6f0a7f052bb851ce760c4c88e0fe0dea18c14b42d5bcf457ac9cfefe3eaa2027f1b847c2ab0c133233618502cfe9207b1e82a5b1d65d0d4a678b58f5ea0ff88
6
+ metadata.gz: b56b571c9aed79bdf0fdce664fa8ae24c152e52ac6804f3621c1597701a0293e4e105e0ce2db482d75640e81d7c8d9d1db085d70d0aa8827290277c87c280f68
7
+ data.tar.gz: a68af4ec2b0f7d02411e543aae1ca8e141d0be7a992e2d57ac6cd3c40e54ed3437ff39df312907914a679c7b75853902d4ab016b562428ae543f0af50730cabf
@@ -140,7 +140,10 @@ module Optimizely
140
140
 
141
141
  # Create and dispatch impression event
142
142
  experiment = config.get_experiment_from_key(experiment_key)
143
- send_impression(config, experiment, variation_key, user_id, attributes)
143
+ send_impression(
144
+ config, experiment, variation_key, '', experiment_key, true,
145
+ Optimizely::DecisionService::DECISION_SOURCES['EXPERIMENT'], user_id, attributes
146
+ )
144
147
 
145
148
  variation_key
146
149
  end
@@ -316,14 +319,23 @@ module Optimizely
316
319
  experiment_key: decision.experiment['key'],
317
320
  variation_key: variation['key']
318
321
  }
319
- # Send event if Decision came from an experiment.
320
- send_impression(config, decision.experiment, variation['key'], user_id, attributes)
321
- else
322
- @logger.log(Logger::DEBUG,
323
- "The user '#{user_id}' is not being experimented on in feature '#{feature_flag_key}'.")
322
+ # Send event if Decision came from a feature test.
323
+ send_impression(
324
+ config, decision.experiment, variation['key'], feature_flag_key, decision.experiment['key'], feature_enabled, source_string, user_id, attributes
325
+ )
326
+ elsif decision.source == Optimizely::DecisionService::DECISION_SOURCES['ROLLOUT'] && config.send_flag_decisions
327
+ send_impression(
328
+ config, decision.experiment, variation['key'], feature_flag_key, decision.experiment['key'], feature_enabled, source_string, user_id, attributes
329
+ )
324
330
  end
325
331
  end
326
332
 
333
+ if decision.nil? && config.send_flag_decisions
334
+ send_impression(
335
+ config, nil, '', feature_flag_key, '', feature_enabled, source_string, user_id, attributes
336
+ )
337
+ end
338
+
327
339
  @notification_center.send_notifications(
328
340
  NotificationCenter::NOTIFICATION_TYPES[:DECISION],
329
341
  Helpers::Constants::DECISION_NOTIFICATION_TYPES['FEATURE'],
@@ -867,15 +879,43 @@ module Optimizely
867
879
  raise InvalidInputError, 'event_dispatcher'
868
880
  end
869
881
 
870
- def send_impression(config, experiment, variation_key, user_id, attributes = nil)
882
+ def send_impression(config, experiment, variation_key, flag_key, rule_key, enabled, rule_type, user_id, attributes = nil)
883
+ if experiment.nil?
884
+ experiment = {
885
+ 'id' => '',
886
+ 'key' => '',
887
+ 'layerId' => '',
888
+ 'status' => '',
889
+ 'variations' => [],
890
+ 'trafficAllocation' => [],
891
+ 'audienceIds' => [],
892
+ 'audienceConditions' => [],
893
+ 'forcedVariations' => {}
894
+ }
895
+ end
896
+
871
897
  experiment_key = experiment['key']
872
- variation_id = config.get_variation_id_from_key(experiment_key, variation_key)
873
- user_event = UserEventFactory.create_impression_event(config, experiment, variation_id, user_id, attributes)
898
+
899
+ variation_id = ''
900
+ variation_id = config.get_variation_id_from_key(experiment_key, variation_key) if experiment_key != ''
901
+
902
+ metadata = {
903
+ flag_key: flag_key,
904
+ rule_key: rule_key,
905
+ rule_type: rule_type,
906
+ variation_key: variation_key,
907
+ enabled: enabled
908
+ }
909
+
910
+ user_event = UserEventFactory.create_impression_event(config, experiment, variation_id, metadata, user_id, attributes)
874
911
  @event_processor.process(user_event)
875
912
  return unless @notification_center.notification_count(NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE]).positive?
876
913
 
877
914
  @logger.log(Logger::INFO, "Activating user '#{user_id}' in experiment '#{experiment_key}'.")
878
- variation = config.get_variation_from_id(experiment_key, variation_id)
915
+
916
+ experiment = nil if experiment_key == ''
917
+ variation = nil
918
+ variation = config.get_variation_from_id(experiment_key, variation_id) unless experiment.nil?
879
919
  log_event = EventFactory.create_log_event(user_event, @logger)
880
920
  @notification_center.send_notifications(
881
921
  NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE],
@@ -40,6 +40,7 @@ module Optimizely
40
40
  attr_reader :revision
41
41
  attr_reader :rollouts
42
42
  attr_reader :version
43
+ attr_reader :send_flag_decisions
43
44
 
44
45
  attr_reader :attribute_key_map
45
46
  attr_reader :audience_id_map
@@ -83,6 +84,7 @@ module Optimizely
83
84
  @bot_filtering = config['botFiltering']
84
85
  @revision = config['revision']
85
86
  @rollouts = config.fetch('rollouts', [])
87
+ @send_flag_decisions = config.fetch('sendFlagDecisions', false)
86
88
 
87
89
  # Json type is represented in datafile as a subtype of string for the sake of backwards compatibility.
88
90
  # Converting it to a first-class json type while creating Project Config
@@ -40,6 +40,7 @@ module Optimizely
40
40
  Decision = Struct.new(:experiment, :variation, :source)
41
41
 
42
42
  DECISION_SOURCES = {
43
+ 'EXPERIMENT' => 'experiment',
43
44
  'FEATURE_TEST' => 'feature-test',
44
45
  'ROLLOUT' => 'rollout'
45
46
  }.freeze
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright 2019, Optimizely and contributors
4
+ # Copyright 2019-2020, Optimizely and contributors
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -17,19 +17,21 @@
17
17
  #
18
18
  module Optimizely
19
19
  class Decision
20
- attr_reader :campaign_id, :experiment_id, :variation_id
20
+ attr_reader :campaign_id, :experiment_id, :variation_id, :metadata
21
21
 
22
- def initialize(campaign_id:, experiment_id:, variation_id:)
22
+ def initialize(campaign_id:, experiment_id:, variation_id:, metadata:)
23
23
  @campaign_id = campaign_id
24
24
  @experiment_id = experiment_id
25
25
  @variation_id = variation_id
26
+ @metadata = metadata
26
27
  end
27
28
 
28
29
  def as_json
29
30
  {
30
31
  campaign_id: @campaign_id,
31
32
  experiment_id: @experiment_id,
32
- variation_id: @variation_id
33
+ variation_id: @variation_id,
34
+ metadata: @metadata
33
35
  }
34
36
  end
35
37
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright 2019, Optimizely and contributors
4
+ # Copyright 2019-2020, Optimizely and contributors
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ require_relative 'user_event'
19
19
  require 'optimizely/helpers/date_time_utils'
20
20
  module Optimizely
21
21
  class ImpressionEvent < UserEvent
22
- attr_reader :user_id, :experiment_layer_id, :experiment_id, :variation_id,
22
+ attr_reader :user_id, :experiment_layer_id, :experiment_id, :variation_id, :metadata,
23
23
  :visitor_attributes, :bot_filtering
24
24
 
25
25
  def initialize(
@@ -28,6 +28,7 @@ module Optimizely
28
28
  experiment_layer_id:,
29
29
  experiment_id:,
30
30
  variation_id:,
31
+ metadata:,
31
32
  visitor_attributes:,
32
33
  bot_filtering:
33
34
  )
@@ -38,6 +39,7 @@ module Optimizely
38
39
  @experiment_layer_id = experiment_layer_id
39
40
  @experiment_id = experiment_id
40
41
  @variation_id = variation_id
42
+ @metadata = metadata
41
43
  @visitor_attributes = visitor_attributes
42
44
  @bot_filtering = bot_filtering
43
45
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright 2019, Optimizely and contributors
4
+ # Copyright 2019-2020, Optimizely and contributors
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -101,10 +101,11 @@ module Optimizely
101
101
  private
102
102
 
103
103
  def create_impression_event_visitor(impression_event)
104
- decision = Optimizely::Decision.new(
104
+ decision = Decision.new(
105
105
  campaign_id: impression_event.experiment_layer_id,
106
106
  experiment_id: impression_event.experiment_id,
107
- variation_id: impression_event.variation_id
107
+ variation_id: impression_event.variation_id,
108
+ metadata: impression_event.metadata
108
109
  )
109
110
 
110
111
  snapshot_event = Optimizely::SnapshotEvent.new(
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright 2019, Optimizely and contributors
4
+ # Copyright 2019-2020, Optimizely and contributors
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@ require_relative 'event_factory'
22
22
  module Optimizely
23
23
  class UserEventFactory
24
24
  # UserEventFactory builds ImpressionEvent and ConversionEvent objects from a given user_event.
25
- def self.create_impression_event(project_config, experiment, variation_id, user_id, user_attributes)
25
+ def self.create_impression_event(project_config, experiment, variation_id, metadata, user_id, user_attributes)
26
26
  # Create impression Event to be sent to the logging endpoint.
27
27
  #
28
28
  # project_config - Instance of ProjectConfig
@@ -42,13 +42,14 @@ module Optimizely
42
42
  ).as_json
43
43
 
44
44
  visitor_attributes = Optimizely::EventFactory.build_attribute_list(user_attributes, project_config)
45
- experiment_layer_id = project_config.experiment_key_map[experiment['key']]['layerId']
45
+ experiment_layer_id = experiment['layerId']
46
46
  Optimizely::ImpressionEvent.new(
47
47
  event_context: event_context,
48
48
  user_id: user_id,
49
49
  experiment_layer_id: experiment_layer_id,
50
50
  experiment_id: experiment['id'],
51
51
  variation_id: variation_id,
52
+ metadata: metadata,
52
53
  visitor_attributes: visitor_attributes,
53
54
  bot_filtering: project_config.bot_filtering
54
55
  )
@@ -46,6 +46,8 @@ module Optimizely
46
46
 
47
47
  def revision; end
48
48
 
49
+ def send_flag_decisions; end
50
+
49
51
  def rollouts; end
50
52
 
51
53
  def experiment_running?(experiment); end
@@ -17,5 +17,5 @@
17
17
  #
18
18
  module Optimizely
19
19
  CLIENT_ENGINE = 'ruby-sdk'
20
- VERSION = '3.6.0'
20
+ VERSION = '3.7.0'
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optimizely-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Optimizely
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-30 00:00:00.000000000 Z
11
+ date: 2020-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler