3333)
3434from ..utils .rule_evaluation_util import evaluate_rule
3535from ..utils .decision_util import evaluate_traffic_and_get_variation
36- from ..utils .impression_util import create_and_send_impression_for_variation_shown
36+ from ..utils .impression_util import (
37+ send_impression_for_variation_shown_batch ,
38+ send_impression_for_variation_shown ,
39+ )
3740from ..models .user .get_flag import GetFlag
3841from ..services .storage_service import StorageService
3942from ..decorators .storage_decorator import StorageDecorator
4245from ..packages .logger .enums .log_level_enum import LogLevelEnum
4346from ..constants .Constants import Constants
4447from ..utils .debugger_service_util import send_debug_event_to_vwo
48+ from ..utils .network_util import get_track_user_payload_data
49+ from ..enums .event_enum import EventEnum
50+ from ..services .settings_manager import SettingsManager
4551
4652
4753class GetFlagApi :
@@ -87,6 +93,7 @@ def get(
8793 stored_data = StorageDecorator ().get_feature_from_storage (
8894 feature_key , context , storage_service
8995 )
96+ batchPayload = []
9097
9198 if stored_data and stored_data .get ("experimentVariationId" ):
9299 if "experimentKey" in stored_data :
@@ -153,24 +160,36 @@ def get(
153160 rollout_rules_to_evaluate : List [CampaignModel ] = []
154161
155162 for rule in roll_out_rules :
156- pre_segmentation_result , whitelisted_object , updated_decision = (
157- evaluate_rule (
158- settings ,
159- feature ,
160- rule ,
161- context ,
162- self ._evaluated_feature_map ,
163- {},
164- storage_service ,
165- decision ,
166- )
163+ (
164+ pre_segmentation_result ,
165+ whitelisted_object ,
166+ updated_decision ,
167+ payload ,
168+ ) = evaluate_rule (
169+ settings ,
170+ feature ,
171+ rule ,
172+ context ,
173+ self ._evaluated_feature_map ,
174+ {},
175+ storage_service ,
176+ decision ,
167177 )
168-
169178 decision .update (updated_decision )
170179
171180 if pre_segmentation_result :
172181 rollout_rules_to_evaluate .append (rule )
173182
183+ if (
184+ SettingsManager .get_instance ().is_gateway_service_provided
185+ and payload is not None
186+ and len (payload ) > 0
187+ ):
188+ send_impression_for_variation_shown (payload , context )
189+ else :
190+ if payload is not None and len (payload ) > 0 :
191+ batchPayload .append (payload )
192+
174193 self ._evaluated_feature_map [feature_key ] = {
175194 "rolloutId" : rule .get_id (),
176195 "rolloutKey" : rule .get_key (),
@@ -194,13 +213,23 @@ def get(
194213 self ._update_integrations_decision_object (
195214 rollout_rules_to_evaluate [0 ], variation , decision
196215 )
197- create_and_send_impression_for_variation_shown (
216+
217+ payload = get_track_user_payload_data (
198218 settings ,
219+ EventEnum .VWO_VARIATION_SHOWN .value ,
199220 rollout_rules_to_evaluate [0 ].get_id (),
200221 variation .get_id (),
201222 context ,
202- feature_key ,
203223 )
224+ if (
225+ SettingsManager .get_instance ().is_gateway_service_provided
226+ and payload is not None
227+ and len (payload ) > 0
228+ ):
229+ send_impression_for_variation_shown (payload , context )
230+ else :
231+ if payload is not None and len (payload ) > 0 :
232+ batchPayload .append (payload )
204233
205234 if not roll_out_rules :
206235 LogManager .get_instance ().debug (
@@ -215,17 +244,20 @@ def get(
215244 meg_group_winner_campaigns = {}
216245
217246 for rule in experiment_rules :
218- pre_segmentation_result , whitelisted_object , updated_decision = (
219- evaluate_rule (
220- settings ,
221- feature ,
222- rule ,
223- context ,
224- self ._evaluated_feature_map ,
225- meg_group_winner_campaigns ,
226- storage_service ,
227- decision ,
228- )
247+ (
248+ pre_segmentation_result ,
249+ whitelisted_object ,
250+ updated_decision ,
251+ payload ,
252+ ) = evaluate_rule (
253+ settings ,
254+ feature ,
255+ rule ,
256+ context ,
257+ self ._evaluated_feature_map ,
258+ meg_group_winner_campaigns ,
259+ storage_service ,
260+ decision ,
229261 )
230262
231263 decision .update (updated_decision )
@@ -234,6 +266,16 @@ def get(
234266 if whitelisted_object is None :
235267 experiment_rules_to_evaluate .append (rule )
236268 else :
269+ if (
270+ SettingsManager .get_instance ().is_gateway_service_provided
271+ and payload is not None
272+ and len (payload ) > 0
273+ ):
274+ send_impression_for_variation_shown (payload , context )
275+ else :
276+ if payload is not None and len (payload ) > 0 :
277+ batchPayload .append (payload )
278+
237279 self ._get_flag_response .set_is_enabled (True )
238280 self ._get_flag_response .set_variables (
239281 whitelisted_object ["variation" ].get_variables ()
@@ -263,13 +305,23 @@ def get(
263305 self ._update_integrations_decision_object (
264306 experiment_rules_to_evaluate [0 ], variation , decision
265307 )
266- create_and_send_impression_for_variation_shown (
308+
309+ payload = get_track_user_payload_data (
267310 settings ,
311+ EventEnum .VWO_VARIATION_SHOWN .value ,
268312 experiment_rules_to_evaluate [0 ].get_id (),
269313 variation .get_id (),
270314 context ,
271- feature_key ,
272315 )
316+ if (
317+ SettingsManager .get_instance ().is_gateway_service_provided
318+ and payload is not None
319+ and len (payload ) > 0
320+ ):
321+ send_impression_for_variation_shown (payload , context )
322+ else :
323+ if payload is not None and len (payload ) > 0 :
324+ batchPayload .append (payload )
273325
274326 if self ._get_flag_response .is_enabled ():
275327 StorageDecorator ().set_data_in_storage (
@@ -310,14 +362,26 @@ def get(
310362 )
311363 )
312364
313- create_and_send_impression_for_variation_shown (
365+ payload = get_track_user_payload_data (
314366 settings ,
367+ EventEnum .VWO_VARIATION_SHOWN .value ,
315368 feature .get_impact_campaign ().get_campaign_id (),
316- (
317- 2 if self ._get_flag_response .is_enabled () else 1
318- ), # 2 is for Variation (flag enabled), 1 is for Control (flag disabled)
319- context ,
320- feature_key ,
369+ (2 if self ._get_flag_response .is_enabled () else 1 ),
370+ context
371+ )
372+ if (
373+ SettingsManager .get_instance ().is_gateway_service_provided
374+ and payload is not None
375+ and len (payload ) > 0
376+ ):
377+ send_impression_for_variation_shown (payload , context )
378+ else :
379+ if payload is not None and len (payload ) > 0 :
380+ batchPayload .append (payload )
381+
382+ if not SettingsManager .get_instance ().is_gateway_service_provided :
383+ send_impression_for_variation_shown_batch (
384+ batchPayload , settings .get_account_id (), settings .get_sdk_key ()
321385 )
322386
323387 return self ._get_flag_response
0 commit comments