PHP code example of abrouter / abrouter-php-client
1. Go to this page and download the library: Download abrouter/abrouter-php-client 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/ */
abrouter / abrouter-php-client example snippets
use Abrouter\Client\Config\Config;
use DI\ContainerBuilder;
use Abrouter\Client\Client;
'04890788ba2c89c4ff21668c60838a00a87b1cf42c9c6b45d6aa8e11174f0d5762b16b6c09b6b822'; //you can find your token in ABRouter dashboard
$di->set(Config::class, new Config($token, 'https://abrouter.com'));
/**
* @var Client $client
*/
$client = $di->make(Abrouter\Client\Client::class);
$userSignature = $_SERSSION['userId'] ?? uniqid();
$experimentId = 'button_color';//experiment id is also there
$runExperimentResult = $client->experiments()->run($userSignature, $experimentId);
$experimentId = $runExperimentResult->getExperimentId(); //form-color
$branchId = $runExperimentResult->getBranchId(); //red
echo '<button style="color: '. $branchId .'">Hello</button>';
use Abrouter\Client\Config\Config;
use DI\ContainerBuilder;
use Abrouter\Client\Client;
use Abrouter\Client\Builders\StatEventBuilder;
* @var Client $client
*/
$client = $di->make(Abrouter\Client\Client::class); // using PHP-DI
$eventBuilder = $this->getContainer()->make(StatEventBuilder::class);
//sending button_click event as button_click+1
$client->statistics()->sendEvent(
$eventBuilder
->incremental()
->event('button_click')
->setUserId($userSignature)
->build()
);
// sending purchase event with purchase amount
$client->statistics()->sendEvent(
$eventBuilder
->summarize()
->event('purchase')
->setValue(30)
->setUserId($userSignature)
->build()
);
use Abrouter\Client\Config\Config;
use DI\ContainerBuilder;
use Abrouter\Client\Client;
use Abrouter\Client\Config\RedisConfig;
use Abrouter\Client\Contracts\KvStorageContract;
use Abrouter\Client\DB\RedisConnection;
use Abrouter\Client\Services\KvStorage\KvStorage;
use Abrouter\Client\Services\TaskManager\TaskManager;
nfig);
$container->set(Config::class, $config);
$kvStorage = $container->make(KvStorage::class);
$container->make(KvStorage::class);
$container->set(
KvStorageContract::class,
$kvStorage
);
$config->setKvStorageConfig($kvStorage);
$container->set(Config::class, $config);
$taskManager = $container->make(TaskManager::class);
$config->setParallelRunConfig(new ParallelRunConfig(true, $taskManager));
bash
$ composer
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.