@@ -140,7 +140,10 @@ def activate(experiment_key, user_id, attributes = nil)
140140
141141 # Create and dispatch impression event
142142 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 ,
145+ Optimizely ::DecisionService ::DECISION_SOURCES [ 'EXPERIMENT' ] , user_id , attributes
146+ )
144147
145148 variation_key
146149 end
@@ -316,14 +319,23 @@ def is_feature_enabled(feature_flag_key, user_id, attributes = nil)
316319 experiment_key : decision . experiment [ 'key' ] ,
317320 variation_key : variation [ 'key' ]
318321 }
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' ] , 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' ] , source_string , user_id , attributes
329+ )
324330 end
325331 end
326332
333+ if decision . nil? && config . send_flag_decisions
334+ send_impression (
335+ config , nil , '' , feature_flag_key , '' , source_string , user_id , attributes
336+ )
337+ end
338+
327339 @notification_center . send_notifications (
328340 NotificationCenter ::NOTIFICATION_TYPES [ :DECISION ] ,
329341 Helpers ::Constants ::DECISION_NOTIFICATION_TYPES [ 'FEATURE' ] ,
@@ -867,15 +879,42 @@ def validate_instantiation_options
867879 raise InvalidInputError , 'event_dispatcher'
868880 end
869881
870- def send_impression ( config , experiment , variation_key , user_id , attributes = nil )
882+ def send_impression ( config , experiment , variation_key , flag_key , rule_key , 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+
871897 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+ }
908+
909+ user_event = UserEventFactory . create_impression_event ( config , experiment , variation_id , metadata , user_id , attributes )
874910 @event_processor . process ( user_event )
875911 return unless @notification_center . notification_count ( NotificationCenter ::NOTIFICATION_TYPES [ :ACTIVATE ] ) . positive?
876912
877913 @logger . log ( Logger ::INFO , "Activating user '#{ user_id } ' in experiment '#{ experiment_key } '." )
878- variation = config . get_variation_from_id ( experiment_key , variation_id )
914+
915+ experiment = nil if experiment_key == ''
916+ variation = nil
917+ variation = config . get_variation_from_id ( experiment_key , variation_id ) unless experiment . nil?
879918 log_event = EventFactory . create_log_event ( user_event , @logger )
880919 @notification_center . send_notifications (
881920 NotificationCenter ::NOTIFICATION_TYPES [ :ACTIVATE ] ,
0 commit comments