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!';
}
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,
]);