@@ -160,8 +160,8 @@ def _validate_user_inputs(self, attributes=None, event_tags=None):
160160
161161 return True
162162
163- def _send_impression_event (self , project_config , experiment , variation , flag_key , rule_key , rule_type , user_id ,
164- attributes ):
163+ def _send_impression_event (self , project_config , experiment , variation , flag_key , rule_key , rule_type , enabled ,
164+ user_id , attributes ):
165165 """ Helper method to send impression event.
166166
167167 Args:
@@ -171,12 +171,13 @@ def _send_impression_event(self, project_config, experiment, variation, flag_key
171171 flag_key: key for a feature flag.
172172 rule_key: key for an experiment.
173173 rule_type: type for the source.
174+ enabled: boolean representing if feature is enabled
174175 user_id: ID for user.
175176 attributes: Dict representing user attributes and values which need to be recorded.
176177 """
177178 variation_id = variation .id if variation is not None else None
178179 user_event = user_event_factory .UserEventFactory .create_impression_event (
179- project_config , experiment , variation_id , flag_key , rule_key , rule_type , user_id , attributes
180+ project_config , experiment , variation_id , flag_key , rule_key , rule_type , enabled , user_id , attributes
180181 )
181182
182183 self .event_processor .process (user_event )
@@ -427,7 +428,7 @@ def activate(self, experiment_key, user_id, attributes=None):
427428 # Create and dispatch impression event
428429 self .logger .info ('Activating user "%s" in experiment "%s".' % (user_id , experiment .key ))
429430 self ._send_impression_event (project_config , experiment , variation , '' , experiment .key ,
430- enums .DecisionSources .EXPERIMENT , user_id , attributes )
431+ enums .DecisionSources .EXPERIMENT , True , user_id , attributes )
431432
432433 return variation .key
433434
@@ -580,25 +581,26 @@ def is_feature_enabled(self, feature_key, user_id, attributes=None):
580581 is_source_experiment = decision .source == enums .DecisionSources .FEATURE_TEST
581582 is_source_rollout = decision .source == enums .DecisionSources .ROLLOUT
582583
584+ if decision .variation :
585+ if decision .variation .featureEnabled is True :
586+ feature_enabled = True
587+
583588 if (is_source_rollout or not decision .variation ) and project_config .get_send_flag_decisions_value ():
584589 self ._send_impression_event (
585590 project_config , decision .experiment , decision .variation , feature .key , decision .experiment .key if
586- decision .experiment else '' , decision .source , user_id , attributes
591+ decision .experiment else '' , decision .source , feature_enabled , user_id , attributes
587592 )
588593
589- if decision .variation :
590- if decision .variation .featureEnabled is True :
591- feature_enabled = True
592- # Send event if Decision came from an experiment.
593- if is_source_experiment :
594- source_info = {
595- 'experiment_key' : decision .experiment .key ,
596- 'variation_key' : decision .variation .key ,
597- }
598- self ._send_impression_event (
599- project_config , decision .experiment , decision .variation , feature .key , decision .experiment .key ,
600- decision .source , user_id , attributes
601- )
594+ # Send event if Decision came from an experiment.
595+ if is_source_experiment and decision .variation :
596+ source_info = {
597+ 'experiment_key' : decision .experiment .key ,
598+ 'variation_key' : decision .variation .key ,
599+ }
600+ self ._send_impression_event (
601+ project_config , decision .experiment , decision .variation , feature .key , decision .experiment .key ,
602+ decision .source , feature_enabled , user_id , attributes
603+ )
602604
603605 if feature_enabled :
604606 self .logger .info ('Feature "%s" is enabled for user "%s".' % (feature_key , user_id ))
0 commit comments