1. Go to this page and download the library: Download vwo/vwo-fme-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vwo / vwo-fme-php-sdk example snippets
$vwoClient = VWO::init([
'sdkKey' => 'vwo_sdk_key',
'accountId' => 'vwo_account_id',
]);
// set user context
$userContext = [ 'id' => 'unique_user_id'];
// returns a flag object
$getFlag = $vwoClient->getFlag('feature_key', $userContext);
// check if flag is enabled
$isFlagEnabled = $getFlag['isEnabled'];
// get variable
$variableValue = $getFlag->getVariable('variable_key', 'default-value');
// track event
$trackRes = $vwoClient->trackEvent('event_name', $userContext);
// set Attribute
$attributes = [
'attribute_key' => 'attribute_value'
];
$setAttribute = $vwoClient->setAttribute($attributes, $userContext);
$featureFlag = $vwoClient->getFlag('feature_key', $userContext);
$isEnabled = $featureFlag->isEnabled();
if ($isEnabled) {
echo 'Feature is enabled!';
// Get and use feature variable with type safety
$variableValue = $featureFlag->getVariable('feature_variable', 'default_value');
echo 'Variable value:', $variableValue;
} else {
echo 'Feature is not enabled!';
}
use vwo\VWO;
// Generate UUID for a user
$userId = 'user-123';
$accountId = '123456';
$uuid = VWO::getUUID($userId, $accountId);
echo 'Generated UUID:', $uuid;
// Output: Generated UUID: CC25A368ADA0542699EAD62489811105
// Two different users bucketed the same way using a shared seed
$context1 = ['id' => 'user_1', 'bucketingSeed' => 'shared_seed'];
$context2 = ['id' => 'user_2', 'bucketingSeed' => 'shared_seed'];
// Both will receive the same variation
$flag1 = $vwoClient->getFlag('feature_key', $context1);
$flag2 = $vwoClient->getFlag('feature_key', $context2);
class StorageConnector {
private $map = [];
public function get($featureKey, $userId) {
$key = $featureKey . '_' . $userId;
return isset($this->map[$key]) ? $this->map[$key] : null;
}
public function set($data) {
$key = $data['featureKey'] . '_' . $data['user'];
// Implement your storage logic here to store the data in your preferred database system using $key
}
}
// Initialize the StorageConnector
$storageConnector = new StorageConnector();
$vwoClient = VWO::init([
'sdkKey' => '32-alpha-numeric-sdk-key',
'accountId' => '123456',
'storage' => $storageConnector,
]);