1. Go to this page and download the library: Download absmartly/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/ */
use \ABSmartly\SDK\SDK;
$sdk = SDK::createWithDefaults(
$endpoint, $apiKey, $environment, $application,
);
use ABSmartly\SDK\Client\ClientConfig;
use ABSmartly\SDK\Client\Client;
use ABSmartly\SDK\Config;
use ABSmartly\SDK\SDK;
use ABSmartly\SDK\Context\ContextConfig;
use ABSmartly\SDK\Context\ContextEventLoggerCallback;
$clientConfig = new ClientConfig('', '', '', '');
$client = new Client($clientConfig);
$config = new Config($client);
$sdk = new SDK($config);
$contextConfig = new ContextConfig();
$contextConfig->setEventLogger(new ContextEventLoggerCallback(
function (string $event, ?object $data) {
// Custom callback
}
));
$context = $sdk->createContext($contextConfig);
use ABSmartly\SDK\Client\ClientConfig;
use ABSmartly\SDK\Context\ContextEventLoggerCallback;
$contextConfig = new ContextConfig();
$contextConfig->setEventLogger(new ContextEventLoggerCallback(
function (string $event, ?object $data) {
// Custom callback
}
));
use \ABSmartly\SDK\Context\ContextEventLoggerCallback;
class CustomLogger implements ContextEventLogger {
public function handleEvent(Context $context, ContextEventLoggerEvent $event): void {
// Process the log event
// e.g
// myLogFunction($event->getEvent(), $event->getData());
}
}
$contextConfig = new ContextConfig();
$contextConfig->setEventLogger(CustomLogger());
$contextConfig = new ContextConfig();
$contextConfig->setUnit('session_id', 'session_id5ebf06d8cb5d8137290c4abb64155584fbdb64d8'); // a unique id identifying the user
$context = $sdk->createContext($contextConfig);
$contextConfig = new ContextConfig();
$contextConfig->setUnit('session_id', 'session_id5ebf06d8cb5d8137290c4abb64155584fbdb64d8'); // a unique id identifying the user
$context = $sdk->createContext($contextConfig);
$anotherContextConfig = new ContextConfig();
$anotherContextConfig->setUnit('session_id', 'session_id5ebf06d8cb5d8137290c4abb64155584fbdb64d8'); // a unique id identifying the user
$anotherContext = $sdk->createContextWithData($anotherContextConfig, $context->getContextData());
$context->refresh();
$context->setUnit('user_id', 143432);
$treatment = $context->getTreatment('exp_test_experiment');
if ($treatment === 0) {
// user is in control group (variant 0)
}
else {
// user is in treatment group
}
$treatment = $context->peekTreatment('exp_test_experiment');
if ($treatment === 0) {
// user is in control group (variant 0)
}
else {
// user is in treatment group
}