1. Go to this page and download the library: Download vwo/vwo-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-php-sdk example snippets
re_once('userStorage.php'); // Optional :if you are using UserStorage service feature
ITH_TOKEN'; // eg: can be found in VWO app - FullStack project
$campaignKey = 'CAMPAIGN_UNIQUE_TEST_KEY';
$userId = 'USER_ID';
$goalIdentifier = 'REPLACE_WITH_CAMPAIGN_GOAL_IDENTIFIER';
// to fetch the settings i.e campaigns, variations and goals
$settingsFile = VWO::getSettingsFile($accountId, $sdkKey);
$sdkConfig = [
'settingsFile' => $settingsFile,
'isDevelopmentMode' => 0, // optional: 1 to enable the dev mode
'logging' => new CustomLogger(), // optional
'userStorageService' => new userStorageService() // optional
];
$vwoClient = new VWO($sdkConfig);
// to get the variation name along with add a visitor hit to vwo app stats
$variation = $vwoClient->activate($campaignKey, $userId, $options);
// Or, to get the variation name
$variation = $vwoClient->getVariationName($campaignKey, $userId, $options);
// add code here to use variation
//...
/**
*send the track api hit to the vwo app stats to increase conversions
* $revenue is optional send in case if there is any revenue inside $options
*/
$vwoClient->track($campaignKey, $userId, $goalIdentifier, $options);
wo\Utils\UserStorageInterface;
Class UserStorage implements UserStorageInterface{
/**
* @param $userId
* @param $campaignKey
*
* @return array
*/
public function get($userId, $campaignKey) {
// search in DB/Storage system
$variation = $db->fetch($userId, $campaignKey); // replace with your implementation
return[
'userId' => $userId,
'campaignKey' => $campaignKey,
'variationName' => $variation
];
}
/**
* @param $campaignUserMapping
* @return bool - could be changed
*/
public function set($campaignUserMapping) {
// S...code to store in DB/storage system
return True;
}
}
wo\Logger\LoggerInterface;
/**
* Class CustomLogger
*/
Class CustomLogger implements LoggerInterface{
/**
* @param $message
* @param $level
*
* @return
*/
public function log($message, $level){
// use $level and log $message to either print or store them for later use
}
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.