Skip to content

Commit c112daf

Browse files
committed
feat: use web UUID to connect with web-insights & web-testing
1 parent 7a2bb07 commit c112daf

File tree

15 files changed

+168
-41
lines changed

15 files changed

+168
-41
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,34 @@ 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.21.0] - 2025-02-18
9+
10+
### Added
11+
12+
- Added support to use the context `id` as the visitor UUID instead of auto-generating one. You can read the visitor UUID from the flag result via `flag->getUUID()` (e.g. to pass to the web client).
13+
```php
14+
use vwo\VWO;
15+
16+
$vwoClient = VWO::init([
17+
'accountId' => '123456',
18+
'sdkKey' => '32-alpha-numeric-sdk-key',
19+
]);
20+
21+
// Default: SDK generates a UUID from id and account
22+
$contextWithGeneratedUuid = ['id' => 'user-123'];
23+
$flag1 = $vwoClient->getFlag('feature-key', $contextWithGeneratedUuid);
24+
25+
// Use your web client UUID by passing it in context.id
26+
$contextWithWebUuid = [
27+
'id' => 'D7E2EAA667909A2DB8A6371FF0975C2A5' // your existing UUID
28+
];
29+
$flag2 = $vwoClient->getFlag('feature-key', $contextWithWebUuid);
30+
31+
// Get the UUID from the flag result (e.g. to pass to web client)
32+
$uuid = $flag1->getUUID();
33+
echo 'Visitor UUID: ' . $uuid;
34+
```
35+
836
## [1.20.0] - 2026-02-18
937

1038
### 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.20.0",
4+
"version": "1.21.0",
55
"keywords": ["vwo", "fme", "sdk"],
66
"license": "Apache-2.0",
77
"authors": [{

src/Api/GetFlag.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function get(
8484
// create debug event props
8585
$debugEventProps = [
8686
'an' => ApiEnum::GET_FLAG,
87-
'uuid' => $context ? $context->getVwoUuid() : null,
87+
'uuid' => $context ? $context->getUUID() : null,
8888
'fk' => $feature ? $feature->getKey() : null,
8989
'sId' => $context ? $context->getSessionId() : null,
9090
];
@@ -113,7 +113,7 @@ public function get(
113113
$context->getId(),
114114
$storedData['experimentKey']
115115
));
116-
return new GetFlagResultUtil(true, $variation->getVariables(), $ruleStatus);
116+
return new GetFlagResultUtil(true, $variation->getVariables(), $ruleStatus, $context->getSessionId(), $context->getUUID());
117117
}
118118
}
119119
} elseif (isset($storedData['rolloutKey']) && isset($storedData['rolloutId'])) {
@@ -153,7 +153,7 @@ public function get(
153153
'featureKey' => $featureKey,
154154
], $debugEventProps));
155155

156-
return new GetFlagResultUtil(false, [], $ruleStatus);
156+
return new GetFlagResultUtil(false, [], $ruleStatus, $context->getSessionId(), $context->getUUID());
157157
}
158158

159159
// Set session ID if not present
@@ -404,7 +404,7 @@ public function get(
404404
ImpressionUtil::SendImpressionForVariationShownInBatch($batchPayload, $serviceContainer);
405405
}
406406

407-
return new GetFlagResultUtil($isEnabled, $variablesForEvaluatedFlag, $ruleStatus, $context->getSessionId());
407+
return new GetFlagResultUtil($isEnabled, $variablesForEvaluatedFlag, $ruleStatus, $context->getSessionId(), $context->getUUID());
408408
}
409409

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

src/Api/TrackEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function track(SettingsModel $settings, string $eventName, ContextModel $
7575
$loggerService->error('EVENT_NOT_FOUND',[
7676
'eventName' => $eventName,
7777
'an' => ApiEnum::TRACK_EVENT,
78-
'uuid' => $context->getVwoUuid(),
78+
'uuid' => $context->getUUID(),
7979
'sId' => $context->getSessionId(),
8080
]);
8181

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.20.0';
43+
const SDK_VERSION = '1.21.0';
4444
const AP = 'server';
4545

4646
const SETTINGS = 'settings';

src/Decorators/StorageDecorator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@ public function setDataInStorage($data, $storageService, ServiceContainer $servi
7373
$loggerService = $serviceContainer->getLoggerService();
7474

7575
if (!$featureKey) {
76-
$loggerService->error("ERROR_STORING_DATA_IN_STORAGE", ["featureKey" => $featureKey, 'an' => ApiEnum::GET_FLAG, 'uuid' => $context->getVwoUuid(), 'sId' => $context->getSessionId()]);
76+
$loggerService->error("ERROR_STORING_DATA_IN_STORAGE", ["featureKey" => $featureKey, 'an' => ApiEnum::GET_FLAG, 'uuid' => $context->getUUID(), 'sId' => $context->getSessionId()]);
7777
return false;
7878
}
7979

8080
if ($context->getId() == null) {
81-
$loggerService->error("ERROR_STORING_DATA_IN_STORAGE", ["context" => $context, 'an' => ApiEnum::GET_FLAG, 'uuid' => $context->getVwoUuid(), 'sId' => $context->getSessionId()]);
81+
$loggerService->error("ERROR_STORING_DATA_IN_STORAGE", ["context" => $context, 'an' => ApiEnum::GET_FLAG, 'uuid' => $context->getUUID(), 'sId' => $context->getSessionId()]);
8282
return false;
8383
}
8484

8585
if ($rolloutKey && !$experimentKey && !$rolloutVariationId) {
86-
$loggerService->error("ERROR_STORING_DATA_IN_STORAGE", ["rolloutKey" => $rolloutKey, "experimentKey" => $experimentKey, "rolloutVariationId" => $rolloutVariationId, 'an' => ApiEnum::GET_FLAG, 'uuid' => $context->getVwoUuid(), 'sId' => $context->getSessionId()]);
86+
$loggerService->error("ERROR_STORING_DATA_IN_STORAGE", ["rolloutKey" => $rolloutKey, "experimentKey" => $experimentKey, "rolloutVariationId" => $rolloutVariationId, 'an' => ApiEnum::GET_FLAG, 'uuid' => $context->getUUID(), 'sId' => $context->getSessionId()]);
8787
return false;
8888
}
8989

9090
if ($experimentKey && !$experimentVariationId) {
91-
$loggerService->error("ERROR_STORING_DATA_IN_STORAGE", ["experimentKey" => $experimentKey, "experimentVariationId" => $experimentVariationId, 'an' => ApiEnum::GET_FLAG, 'uuid' => $context->getVwoUuid(), 'sId' => $context->getSessionId()]);
91+
$loggerService->error("ERROR_STORING_DATA_IN_STORAGE", ["experimentKey" => $experimentKey, "experimentVariationId" => $experimentVariationId, 'an' => ApiEnum::GET_FLAG, 'uuid' => $context->getUUID(), 'sId' => $context->getSessionId()]);
9292
return false;
9393
}
9494

src/Models/SettingsModel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ class SettingsModel {
3131
private $accountId;
3232
private $version;
3333
private $collectionPrefix;
34+
private $isWebConnectivityEnabled;
3435

3536
public function __construct($settings) {
3637
$this->sdkKey = isset($settings->sK) ? $settings->sK : (isset($settings->sdkKey) ? $settings->sdkKey : null);
3738
$this->accountId = isset($settings->a) ? $settings->a : (isset($settings->accountId) ? $settings->accountId : null);
3839
$this->version = isset($settings->v) ? $settings->v : (isset($settings->version) ? $settings->version : null);
3940
$this->collectionPrefix = isset($settings->collectionPrefix) ? $settings->collectionPrefix : null;
41+
$this->isWebConnectivityEnabled = isset($settings->isWebConnectivityEnabled) ? $settings->isWebConnectivityEnabled : true;
4042

4143
if (isset($settings->f) || isset($settings->features)) {
4244
$featureList = isset($settings->f) ? $settings->f : $settings->features;
@@ -87,6 +89,10 @@ public function getCampaignGroups() {
8789
public function getGroups() {
8890
return $this->groups;
8991
}
92+
93+
public function isWebConnectivityEnabled() {
94+
return $this->isWebConnectivityEnabled;
95+
}
9096

9197
public function toArray(): array {
9298
return json_decode(json_encode($this), true);

src/Models/User/ContextModel.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
use vwo\Services\SettingsService;
2222
use vwo\Utils\UuidUtil;
23+
use vwo\Utils\FunctionUtil;
2324

2425
class ContextModel
2526
{
@@ -30,7 +31,7 @@ class ContextModel
3031
private $variationTargetingVariables = [];
3132
private $_vwo;
3233
private $postSegmentationVariables = [];
33-
private $_vwo_uuid;
34+
private $uuid;
3435
private $sessionId;
3536

3637
public function modelFromDictionary($context)
@@ -54,12 +55,18 @@ public function modelFromDictionary($context)
5455
if (isset($context['postSegmentationVariables'])) {
5556
$this->postSegmentationVariables = $context['postSegmentationVariables'];
5657
}
57-
$this->_vwo_uuid = UuidUtil::getUUID($this->id, SettingsService::instance()->accountId);
5858

5959
if (isset($context['sessionId'])) {
6060
$this->sessionId = $context['sessionId'];
6161
}
6262

63+
// set uuid in context if available, otherwise generate a new one
64+
if (isset($context['uuid'])) {
65+
$this->uuid = $context['uuid'];
66+
} else {
67+
$this->uuid = UuidUtil::getUUID($this->id, SettingsService::instance()->accountId);
68+
}
69+
6370
return $this;
6471
}
6572

@@ -128,9 +135,9 @@ public function setSessionId($sessionId)
128135
$this->sessionId = $sessionId;
129136
}
130137

131-
public function getVwoUuid()
138+
public function getUUID()
132139
{
133-
return $this->_vwo_uuid;
140+
return $this->uuid;
134141
}
135142
}
136143

src/Packages/SegmentationEvaluator/Core/SegmentationManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function setContextualData(ServiceContainer $serviceContainer, $feature,
9090
$vwoData = GatewayServiceUtil::getFromGatewayService($serviceContainer, $params, UrlEnum::GET_USER_DATA, $context);
9191
$context->setVwo((new ContextVWOModel())->modelFromDictionary($vwoData));
9292
} catch (\Exception $err) {
93-
$loggerService->error('ERROR_SETTING_SEGMENTATION_CONTEXT', ['err' => $err->getMessage(), 'an' => ApiEnum::GET_FLAG, 'uuid' => $context->getVwoUuid(), 'sId' => $context->getSessionId()]);
93+
$loggerService->error('ERROR_SETTING_SEGMENTATION_CONTEXT', ['err' => $err->getMessage(), 'an' => ApiEnum::GET_FLAG, 'uuid' => $context->getUUID(), 'sId' => $context->getSessionId()]);
9494
}
9595
}
9696
}

src/Packages/SegmentationEvaluator/Evaluators/SegmentEvaluator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function checkLocationPreSegmentation($locationMap)
188188
$ipAddress = $this->context->getIpAddress(); // Use the getter method
189189

190190
if (empty($ipAddress)) {
191-
$this->serviceContainer->getLoggerService()->error('INVALID_IP_ADDRESS_IN_CONTEXT_FOR_PRE_SEGMENTATION', ['an' => ApiEnum::GET_FLAG, 'uuid' => $this->context->getVwoUuid(), 'sId' => $this->context->getSessionId()]);
191+
$this->serviceContainer->getLoggerService()->error('INVALID_IP_ADDRESS_IN_CONTEXT_FOR_PRE_SEGMENTATION', ['an' => ApiEnum::GET_FLAG, 'uuid' => $this->context->getUUID(), 'sId' => $this->context->getSessionId()]);
192192
return false;
193193
}
194194

@@ -204,7 +204,7 @@ public function checkUserAgentParser($uaParserMap)
204204
$userAgent = $this->context->getUserAgent(); // Use the getter method
205205

206206
if (empty($userAgent)) {
207-
$this->serviceContainer->getLoggerService()->error('INVALID_USER_AGENT_IN_CONTEXT_FOR_PRE_SEGMENTATION', ['an' => ApiEnum::GET_FLAG, 'uuid' => $this->context->getVwoUuid(), 'sId' => $this->context->getSessionId()]);
207+
$this->serviceContainer->getLoggerService()->error('INVALID_USER_AGENT_IN_CONTEXT_FOR_PRE_SEGMENTATION', ['an' => ApiEnum::GET_FLAG, 'uuid' => $this->context->getUUID(), 'sId' => $this->context->getSessionId()]);
208208
return false;
209209
}
210210

0 commit comments

Comments
 (0)