@@ -137,6 +137,9 @@ def get_variation(experiment_key, user_id, attributes = nil)
137137 } , @logger , Logger ::ERROR
138138 )
139139
140+ experiment = @config . get_experiment_from_key ( experiment_key )
141+ return nil if experiment . nil?
142+
140143 unless user_inputs_valid? ( attributes )
141144 @logger . log ( Logger ::INFO , "Not activating user '#{ user_id } ." )
142145 return nil
@@ -145,10 +148,14 @@ def get_variation(experiment_key, user_id, attributes = nil)
145148 variation_id = @decision_service . get_variation ( experiment_key , user_id , attributes )
146149 variation = @config . get_variation_from_id ( experiment_key , variation_id ) unless variation_id . nil?
147150 variation_key = variation [ 'key' ] if variation
148-
151+ decision_notification_type = if @config . feature_experiment? ( experiment [ 'id' ] )
152+ Helpers ::Constants ::DECISION_NOTIFICATION_TYPES [ 'FEATURE_TEST' ]
153+ else
154+ Helpers ::Constants ::DECISION_NOTIFICATION_TYPES [ 'AB_TEST' ]
155+ end
149156 @notification_center . send_notifications (
150157 NotificationCenter ::NOTIFICATION_TYPES [ :DECISION ] ,
151- Helpers :: Constants :: DECISION_INFO_TYPES [ 'EXPERIMENT' ] , user_id , ( attributes || { } ) ,
158+ decision_notification_type , user_id , ( attributes || { } ) ,
152159 experiment_key : experiment_key ,
153160 variation_key : variation_key
154161 )
@@ -264,14 +271,16 @@ def is_feature_enabled(feature_flag_key, user_id, attributes = nil)
264271 decision = @decision_service . get_variation_for_feature ( feature_flag , user_id , attributes )
265272
266273 feature_enabled = false
267- source_string = Optimizely ::DecisionService ::DECISION_SOURCE_ROLLOUT
274+ source_string = Optimizely ::DecisionService ::DECISION_SOURCES [ 'ROLLOUT' ]
268275 if decision . is_a? ( Optimizely ::DecisionService ::Decision )
269276 variation = decision [ 'variation' ]
270277 feature_enabled = variation [ 'featureEnabled' ]
271- if decision . source == Optimizely ::DecisionService ::DECISION_SOURCE_EXPERIMENT
272- source_string = Optimizely ::DecisionService ::DECISION_SOURCE_EXPERIMENT
273- experiment_key = decision . experiment [ 'key' ]
274- variation_key = variation [ 'key' ]
278+ if decision . source == Optimizely ::DecisionService ::DECISION_SOURCES [ 'FEATURE_TEST' ]
279+ source_string = Optimizely ::DecisionService ::DECISION_SOURCES [ 'FEATURE_TEST' ]
280+ source_info = {
281+ experiment_key : decision . experiment [ 'key' ] ,
282+ variation_key : variation [ 'key' ]
283+ }
275284 # Send event if Decision came from an experiment.
276285 send_impression ( decision . experiment , variation [ 'key' ] , user_id , attributes )
277286 else
@@ -282,13 +291,12 @@ def is_feature_enabled(feature_flag_key, user_id, attributes = nil)
282291
283292 @notification_center . send_notifications (
284293 NotificationCenter ::NOTIFICATION_TYPES [ :DECISION ] ,
285- Helpers ::Constants ::DECISION_INFO_TYPES [ 'FEATURE' ] ,
294+ Helpers ::Constants ::DECISION_NOTIFICATION_TYPES [ 'FEATURE' ] ,
286295 user_id , ( attributes || { } ) ,
287296 feature_key : feature_flag_key ,
288297 feature_enabled : feature_enabled ,
289- source : source_string . upcase ,
290- source_experiment_key : experiment_key ,
291- source_variation_key : variation_key
298+ source : source_string ,
299+ source_info : source_info || { }
292300 )
293301
294302 if feature_enabled == true
@@ -481,22 +489,23 @@ def get_feature_variable_for_type(feature_flag_key, variable_key, variable_type,
481489 return nil if variable . nil?
482490
483491 feature_enabled = false
484-
485492 # Returns nil if type differs
486493 if variable [ 'type' ] != variable_type
487494 @logger . log ( Logger ::WARN ,
488495 "Requested variable as type '#{ variable_type } ' but variable '#{ variable_key } ' is of type '#{ variable [ 'type' ] } '." )
489496 return nil
490497 else
491- source_string = Optimizely ::DecisionService ::DECISION_SOURCE_ROLLOUT
498+ source_string = Optimizely ::DecisionService ::DECISION_SOURCES [ 'ROLLOUT' ]
492499 decision = @decision_service . get_variation_for_feature ( feature_flag , user_id , attributes )
493500 variable_value = variable [ 'defaultValue' ]
494501 if decision
495502 variation = decision [ 'variation' ]
496- if decision [ 'source' ] == Optimizely ::DecisionService ::DECISION_SOURCE_EXPERIMENT
497- experiment_key = decision . experiment [ 'key' ]
498- variation_key = variation [ 'key' ]
499- source_string = Optimizely ::DecisionService ::DECISION_SOURCE_EXPERIMENT
503+ if decision [ 'source' ] == Optimizely ::DecisionService ::DECISION_SOURCES [ 'FEATURE_TEST' ]
504+ source_info = {
505+ experiment_key : decision . experiment [ 'key' ] ,
506+ variation_key : variation [ 'key' ]
507+ }
508+ source_string = Optimizely ::DecisionService ::DECISION_SOURCES [ 'FEATURE_TEST' ]
500509 end
501510 feature_enabled = variation [ 'featureEnabled' ]
502511 if feature_enabled == true
@@ -524,15 +533,14 @@ def get_feature_variable_for_type(feature_flag_key, variable_key, variable_type,
524533
525534 @notification_center . send_notifications (
526535 NotificationCenter ::NOTIFICATION_TYPES [ :DECISION ] ,
527- Helpers ::Constants ::DECISION_INFO_TYPES [ 'FEATURE_VARIABLE' ] , user_id , ( attributes || { } ) ,
536+ Helpers ::Constants ::DECISION_NOTIFICATION_TYPES [ 'FEATURE_VARIABLE' ] , user_id , ( attributes || { } ) ,
528537 feature_key : feature_flag_key ,
529538 feature_enabled : feature_enabled ,
539+ source : source_string ,
530540 variable_key : variable_key ,
531541 variable_type : variable_type ,
532542 variable_value : variable_value ,
533- source : source_string . upcase ,
534- source_experiment_key : experiment_key ,
535- source_variation_key : variation_key
543+ source_info : source_info || { }
536544 )
537545
538546 variable_value
0 commit comments