3737use vwo \Utils \ImpressionUtil ;
3838use vwo \Utils \GetFlagResultUtil ;
3939use vwo \Utils \RuleEvaluationUtil ;
40+ use vwo \Utils \NetworkUtil ;
41+ use vwo \Enums \EventEnum ;
42+ use vwo \Services \SettingsService ;
4043
4144class GetFlag
4245{
@@ -57,6 +60,7 @@ public function get(
5760 $ evaluatedFeatureMap = [];
5861 $ storageService = new StorageService ();
5962 $ ruleStatus = [];
63+ $ batchPayload = [];
6064
6165 // Get feature object from feature key
6266 $ feature = FunctionUtil::getFeatureFromKey ($ settings , $ featureKey );
@@ -155,6 +159,18 @@ public function get(
155159 );
156160
157161 if ($ evaluateRuleResult ['preSegmentationResult ' ]) {
162+ $ payload = $ evaluateRuleResult ['payload ' ];
163+ if (!$ isDebuggerUsed ) {
164+ if (SettingsService::instance ()->isGatewayServiceProvided && $ payload !== null ) {
165+ ImpressionUtil::SendImpressionForVariationShown ($ settings , $ payload , $ context );
166+ } else {
167+ //push this payload to the batch payload
168+ if ($ payload !== null ) {
169+ $ batchPayload [] = $ payload ;
170+ }
171+ }
172+ }
173+
158174 $ evaluatedFeatureMap [$ featureKey ] = [
159175 'rolloutId ' => $ rule ->getId (),
160176 'rolloutKey ' => $ rule ->getKey (),
@@ -180,12 +196,24 @@ public function get(
180196 $ this ->updateIntegrationsDecisionObject ($ passedRolloutCampaign , $ variation , $ passedRulesInformation , $ decision );
181197
182198 if (!$ isDebuggerUsed ) {
183- ImpressionUtil::createAndSendImpressionForVariationShown (
199+ //push this payload to the batch payload
200+ $ networkUtil = new NetworkUtil ();
201+ $ payload = $ networkUtil ->getTrackUserPayloadData (
184202 $ settings ,
203+ EventEnum::VWO_VARIATION_SHOWN ,
185204 $ passedRolloutCampaign ->getId (),
186205 $ variation ->getId (),
187206 $ context
188207 );
208+
209+ if (SettingsService::instance ()->isGatewayServiceProvided && $ payload !== null ) {
210+ ImpressionUtil::SendImpressionForVariationShown ($ settings , $ payload , $ context );
211+ } else {
212+ //push this payload to the batch payload
213+ if ($ payload !== null ) {
214+ $ batchPayload [] = $ payload ;
215+ }
216+ }
189217 }
190218 }
191219 }
@@ -218,6 +246,14 @@ public function get(
218246 $ experimentRulesToEvaluate [] = $ rule ;
219247 } else {
220248 $ isEnabled = true ;
249+ $ payload = $ evaluateRuleResult ['payload ' ];
250+ if (SettingsService::instance ()->isGatewayServiceProvided && $ payload !== null ) {
251+ ImpressionUtil::SendImpressionForVariationShown ($ settings , $ payload , $ context );
252+ } else {
253+ if ($ payload !== null ) {
254+ $ batchPayload [] = $ payload ;
255+ }
256+ }
221257 $ experimentVariationToReturn = $ evaluateRuleResult ['whitelistedObject ' ]['variation ' ];
222258
223259 $ passedRulesInformation = array_merge ($ passedRulesInformation , [
@@ -245,12 +281,23 @@ public function get(
245281 $ this ->updateIntegrationsDecisionObject ($ campaign , $ variation , $ passedRulesInformation , $ decision );
246282
247283 if (!$ isDebuggerUsed ) {
248- ImpressionUtil::createAndSendImpressionForVariationShown (
284+ // Construct payload data for tracking the user
285+ $ networkUtil = new NetworkUtil ();
286+ $ payload = $ networkUtil ->getTrackUserPayloadData (
249287 $ settings ,
288+ EventEnum::VWO_VARIATION_SHOWN ,
250289 $ campaign ->getId (),
251290 $ variation ->getId (),
252291 $ context
253292 );
293+ if (SettingsService::instance ()->isGatewayServiceProvided && $ payload !== null ) {
294+ ImpressionUtil::SendImpressionForVariationShown ($ settings , $ payload , $ context );
295+ } else {
296+ //push this payload to the batch payload
297+ if ($ payload !== null ) {
298+ $ batchPayload [] = $ payload ;
299+ }
300+ }
254301 }
255302 }
256303 }
@@ -282,12 +329,23 @@ public function get(
282329 ));
283330
284331 if (!$ isDebuggerUsed ) {
285- ImpressionUtil::createAndSendImpressionForVariationShown (
332+ // Construct payload data for tracking the user
333+ $ networkUtil = new NetworkUtil ();
334+ $ payload = $ networkUtil ->getTrackUserPayloadData (
286335 $ settings ,
336+ EventEnum::VWO_VARIATION_SHOWN ,
287337 $ feature ->getImpactCampaign ()->getCampaignId (),
288338 $ isEnabled ? 2 : 1 ,
289339 $ context
290340 );
341+ if (SettingsService::instance ()->isGatewayServiceProvided && $ payload !== null ) {
342+ ImpressionUtil::SendImpressionForVariationShown ($ settings , $ payload , $ context );
343+ } else {
344+ //push this payload to the batch payload
345+ if ($ payload !== null ) {
346+ $ batchPayload [] = $ payload ;
347+ }
348+ }
291349 }
292350 }
293351
@@ -299,6 +357,10 @@ public function get(
299357 $ variablesForEvaluatedFlag = $ rolloutVariationToReturn ->getVariables ();
300358 }
301359
360+ if (!SettingsService::instance ()->isGatewayServiceProvided ) {
361+ ImpressionUtil::SendImpressionForVariationShownInBatch ($ batchPayload );
362+ }
363+
302364 return new GetFlagResultUtil ($ isEnabled , $ variablesForEvaluatedFlag , $ ruleStatus );
303365 }
304366
0 commit comments