Skip to content

Commit 2073a7a

Browse files
sakshamg1304rohitesh-wingify
authored andcommitted
feat: support for VWO internal debugger
1 parent e45e349 commit 2073a7a

File tree

8 files changed

+70
-39
lines changed

8 files changed

+70
-39
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.7.6] - 2025-05-28
9+
10+
### Added
11+
12+
- Support for VWO Internal Debugger
13+
814
## [1.7.5] - 2025-05-13
915

1016
### Added

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vwo/vwo-fme-php-sdk",
33

4-
"version": "1.7.5",
4+
"version": "1.7.6",
55
"keywords": ["vwo", "fme", "sdk"],
66
"license": "Apache-2.0",
77
"authors": [{

src/Api/GetFlag.php

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function get(
4444
string $featureKey,
4545
SettingsModel $settings,
4646
ContextModel $context,
47-
HooksService $hooksService
47+
HooksService $hooksService,
48+
bool $isDebuggerUsed = false
4849
) {
4950
$ruleEvaluationUtil = new RuleEvaluationUtil();
5051
$isEnabled = false;
@@ -55,6 +56,7 @@ public function get(
5556
$passedRulesInformation = [];
5657
$evaluatedFeatureMap = [];
5758
$storageService = new StorageService();
59+
$ruleStatus = [];
5860

5961
// Get feature object from feature key
6062
$feature = FunctionUtil::getFeatureFromKey($settings, $featureKey);
@@ -89,7 +91,7 @@ public function get(
8991
$storedData['experimentKey']
9092
));
9193

92-
return new GetFlagResultUtil(true, $variation->getVariables(), []);
94+
return new GetFlagResultUtil(true, $variation->getVariables(), $ruleStatus);
9395
}
9496
}
9597
} elseif (isset($storedData['rolloutKey'], $storedData['rolloutId'])) {
@@ -130,7 +132,7 @@ public function get(
130132
$featureKey
131133
));
132134

133-
return new GetFlagResultUtil(false, [], []);
135+
return new GetFlagResultUtil(false, [], $ruleStatus);
134136
}
135137

136138
SegmentationManager::instance()->setContextualData($settings, $feature, $context);
@@ -148,7 +150,8 @@ public function get(
148150
$evaluatedFeatureMap,
149151
$megGroupWinnerCampaigns,
150152
$storageService,
151-
$decision
153+
$decision,
154+
$isDebuggerUsed
152155
);
153156

154157
if ($evaluateRuleResult['preSegmentationResult']) {
@@ -176,12 +179,14 @@ public function get(
176179

177180
$this->updateIntegrationsDecisionObject($passedRolloutCampaign, $variation, $passedRulesInformation, $decision);
178181

179-
ImpressionUtil::createAndSendImpressionForVariationShown(
180-
$settings,
181-
$passedRolloutCampaign->getId(),
182-
$variation->getId(),
183-
$context
184-
);
182+
if (!$isDebuggerUsed) {
183+
ImpressionUtil::createAndSendImpressionForVariationShown(
184+
$settings,
185+
$passedRolloutCampaign->getId(),
186+
$variation->getId(),
187+
$context
188+
);
189+
}
185190
}
186191
}
187192
} else if (count($rollOutRules) === 0) {
@@ -204,7 +209,8 @@ public function get(
204209
$evaluatedFeatureMap,
205210
$megGroupWinnerCampaigns,
206211
$storageService,
207-
$decision
212+
$decision,
213+
$isDebuggerUsed
208214
);
209215

210216
if ($evaluateRuleResult['preSegmentationResult']) {
@@ -238,12 +244,14 @@ public function get(
238244

239245
$this->updateIntegrationsDecisionObject($campaign, $variation, $passedRulesInformation, $decision);
240246

241-
ImpressionUtil::createAndSendImpressionForVariationShown(
242-
$settings,
243-
$campaign->getId(),
244-
$variation->getId(),
245-
$context
246-
);
247+
if (!$isDebuggerUsed) {
248+
ImpressionUtil::createAndSendImpressionForVariationShown(
249+
$settings,
250+
$campaign->getId(),
251+
$variation->getId(),
252+
$context
253+
);
254+
}
247255
}
248256
}
249257
}
@@ -273,12 +281,14 @@ public function get(
273281
$context->getId()
274282
));
275283

276-
ImpressionUtil::createAndSendImpressionForVariationShown(
277-
$settings,
278-
$feature->getImpactCampaign()->getCampaignId(),
279-
$isEnabled ? 2 : 1,
280-
$context
281-
);
284+
if (!$isDebuggerUsed) {
285+
ImpressionUtil::createAndSendImpressionForVariationShown(
286+
$settings,
287+
$feature->getImpactCampaign()->getCampaignId(),
288+
$isEnabled ? 2 : 1,
289+
$context
290+
);
291+
}
282292
}
283293

284294
$variablesForEvaluatedFlag = [];
@@ -289,7 +299,7 @@ public function get(
289299
$variablesForEvaluatedFlag = $rolloutVariationToReturn->getVariables();
290300
}
291301

292-
return new GetFlagResultUtil($isEnabled, $variablesForEvaluatedFlag, []);
302+
return new GetFlagResultUtil($isEnabled, $variablesForEvaluatedFlag, $ruleStatus);
293303
}
294304

295305
private function updateIntegrationsDecisionObject(CampaignModel $campaign, VariationModel $variation, array &$passedRulesInformation, array &$decision)

src/Api/SetAttribute.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface ISetAttribute
3131
* @param array $attributes Key-value map of attributes.
3232
* @param ContextModel $context Context containing user information.
3333
*/
34-
public function setAttribute(SettingsModel $settings, array $attributes, ContextModel $context);
34+
public function setAttribute(SettingsModel $settings, array $attributes, ContextModel $context, bool $isDebuggerUsed = false);
3535
}
3636

3737
class SetAttribute implements ISetAttribute
@@ -42,9 +42,11 @@ class SetAttribute implements ISetAttribute
4242
* @param array $attributes Key-value map of attributes.
4343
* @param ContextModel $context Context containing user information.
4444
*/
45-
public function setAttribute(SettingsModel $settings, array $attributes, ContextModel $context)
45+
public function setAttribute(SettingsModel $settings, array $attributes, ContextModel $context, bool $isDebuggerUsed = false)
4646
{
47-
$this->createImpressionForAttributes($settings, $attributes, $context);
47+
if (!$isDebuggerUsed) {
48+
$this->createImpressionForAttributes($settings, $attributes, $context);
49+
}
4850
}
4951

5052
/**

src/Api/TrackEvent.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface ITrack
4040
* @param HooksService $hooksService Manager for handling hooks and callbacks.
4141
* @return array Returns an array indicating the success or failure of the event tracking.
4242
*/
43-
public function track(SettingsModel $settings, string $eventName, ContextModel $context, array $eventProperties, HooksService $hooksService): array;
43+
public function track(SettingsModel $settings, string $eventName, ContextModel $context, array $eventProperties, HooksService $hooksService, bool $isDebuggerUsed = false): array;
4444
}
4545

4646
class TrackEvent implements ITrack
@@ -55,11 +55,14 @@ class TrackEvent implements ITrack
5555
* @param HooksService $hooksService Manager for handling hooks and callbacks.
5656
* @return array Returns an array indicating the success or failure of the event tracking.
5757
*/
58-
public function track(SettingsModel $settings, string $eventName, ContextModel $context, array $eventProperties, HooksService $hooksService): array
58+
public function track(SettingsModel $settings, string $eventName, ContextModel $context, array $eventProperties, HooksService $hooksService, bool $isDebuggerUsed = false): array
5959
{
6060
if (FunctionUtil::doesEventBelongToAnyFeature($eventName, $settings)) {
6161
// Create an impression for the track event
62-
$this->createImpressionForTrack($settings, $eventName, $context, $eventProperties);
62+
// if settings passed in init options is true, then we don't need to send an impression
63+
if (!$isDebuggerUsed) {
64+
$this->createImpressionForTrack($settings, $eventName, $context, $eventProperties);
65+
}
6366

6467
// Set and execute integration callback for the track event
6568
$hooksService->set(['eventName' => $eventName, 'api' => ApiEnum::TRACK]);

src/Constants/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Constants {
4040
const DEFAULT_EVENTS_PER_REQUEST = 100;
4141
const SDK_NAME = 'vwo-fme-php-sdk';
4242

43-
const SDK_VERSION = '1.7.5';
43+
const SDK_VERSION = '1.7.6';
4444
const AP = 'server';
4545

4646
const SETTINGS = 'settings';

src/Utils/RuleEvaluationUtil.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class RuleEvaluationUtil
4444
* @param array $decision - The decision object that will be updated based on the evaluation.
4545
* @return array An array containing the result of the pre-segmentation and the whitelisted object, if any.
4646
*/
47-
public static function evaluateRule($settings, $feature, $campaign, $context, &$evaluatedFeatureMap, &$megGroupWinnerCampaigns, $storageService, &$decision)
47+
public static function evaluateRule($settings, $feature, $campaign, $context, &$evaluatedFeatureMap, &$megGroupWinnerCampaigns, $storageService, &$decision, $isDebuggerUsed = false)
4848
{
4949
// Perform whitelisting and pre-segmentation checks
5050
list($preSegmentationResult, $whitelistedObject) = DecisionUtil::checkWhitelistingAndPreSeg(
@@ -68,7 +68,10 @@ public static function evaluateRule($settings, $feature, $campaign, $context, &$
6868
]);
6969

7070
// Send an impression for the variation shown
71-
ImpressionUtil::createAndSendImpressionForVariationShown($settings, $campaign->getId(), $whitelistedObject['variation']->getId(), $context);
71+
// if settings passed in init options is true, then we don't need to send an impression
72+
if (!$isDebuggerUsed) {
73+
ImpressionUtil::createAndSendImpressionForVariationShown($settings, $campaign->getId(), $whitelistedObject['variation']->getId(), $context);
74+
}
7275
}
7376

7477
// Return the results of the evaluation

src/VWOClient.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public function getFlag(string $featureKey, $context) {
7474
[]
7575
);
7676

77+
//check if isDebuggerUsed is set in options
78+
$isDebuggerUsed = isset($this->options['isDebuggerUsed']);
79+
80+
7781
try {
7882
$hookManager = new HooksService($this->options);
7983

@@ -98,7 +102,7 @@ public function getFlag(string $featureKey, $context) {
98102
$contextModel = new ContextModel();
99103
$contextModel->modelFromDictionary($context);
100104

101-
return (new GetFlag())->get($featureKey, $this->settings, $contextModel, $hookManager);
105+
return (new GetFlag())->get($featureKey, $this->settings, $contextModel, $hookManager, $isDebuggerUsed);
102106
} catch (\Throwable $error) {
103107
LogManager::instance()->error("API - $apiName failed to execute. Error: " . $error->getMessage());
104108
return $defaultReturnValue;
@@ -107,6 +111,8 @@ public function getFlag(string $featureKey, $context) {
107111

108112
public function trackEvent(string $eventName, $context, $eventProperties = []) {
109113
$apiName = 'trackEvent';
114+
//check if isDebuggerUsed is set in options
115+
$isDebuggerUsed = isset($this->options['isDebuggerUsed']);
110116

111117
try {
112118
$hookManager = new HooksService($this->options);
@@ -136,7 +142,7 @@ public function trackEvent(string $eventName, $context, $eventProperties = []) {
136142
$contextModel = new ContextModel();
137143
$contextModel->modelFromDictionary($context);
138144

139-
return (new TrackEvent())->track($this->settings, $eventName, $contextModel, $eventProperties, $hookManager);
145+
return (new TrackEvent())->track($this->settings, $eventName, $contextModel, $eventProperties, $hookManager, $isDebuggerUsed);
140146
} catch (\Throwable $error) {
141147
LogManager::instance()->error("API - $apiName failed to execute. Error: " . $error->getMessage());
142148
return [$eventName => false];
@@ -147,7 +153,8 @@ public function trackEvent(string $eventName, $context, $eventProperties = []) {
147153
public function setAttribute($attributesOrAttributeValue = null, $attributeValueOrContext = null, $context = null) {
148154

149155
$apiName = 'setAttribute';
150-
156+
$isDebuggerUsed = isset($this->options['isDebuggerUsed']);
157+
151158
try {
152159
LogManager::instance()->debug("API Called: $apiName");
153160

@@ -177,7 +184,7 @@ public function setAttribute($attributesOrAttributeValue = null, $attributeValue
177184

178185
// Create the attributes map from key-value
179186
$attributes = [$attributesOrAttributeValue => $attributeValueOrContext];
180-
(new SetAttribute())->setAttribute($this->settings, $attributes, $contextModel);
187+
(new SetAttribute())->setAttribute($this->settings, $attributes, $contextModel, $isDebuggerUsed);
181188

182189
} else {
183190
// Case where attributeKey is an array (multiple attributes)
@@ -218,7 +225,7 @@ public function setAttribute($attributesOrAttributeValue = null, $attributeValue
218225
$contextModel->modelFromDictionary($context);
219226

220227
// Proceed with setting the attributes if validation is successful
221-
(new SetAttribute())->setAttribute($this->settings, $attributes, $contextModel);
228+
(new SetAttribute())->setAttribute($this->settings, $attributes, $contextModel, $isDebuggerUsed);
222229
}
223230
} catch (\Throwable $error) {
224231
LogManager::instance()->error("API - $apiName failed to execute. Error: " . $error->getMessage());

0 commit comments

Comments
 (0)