PHP client library for SeatGeak's Sixpack ab testing framework.
- Install Composer.
- In the root of your project install sixpack via
composer require snpy/sixpack-php. - If computer autoloader is not already included put
require 'vendor/autoload.php';at the top of you script.
Basic example:
The PHP client stores a unique client id in the current user's cookie by default.
use SeatGeak\Sixpack\Session\CookieSession as Session;
$response = (new Session())->participate('experiment-name', ['blue', 'red']);
$variant = $response->getAlternativeName();
if ('blue' === $variant) {
//
// do something "blue"
//
} else {
//
// do something "red"
//
}Each session has a clientId associated with it that must be preserved across requests. The PHP client handles this automatically. If you'd wish to change that behaviour, you can do so like this:
use SeatGeak\Sixpack\Session\CookielessSession as Session;
$clientId = PDO::findClientId();
$session = new Session(['clientId' => $clientId]);
$session->convert('experiment-name');
$response = $session->participate('experiment-name', ['blue', 'red']);
empty($clientId) && PDO::saveClientId($response->getClientId());All possible options for the CookielessSession c-tor:
- clientId - custom client ID; use when you don't want to use cookies; default: NULL,
- baseUrl - Sixpack Server's location on the web; default: http://localhost:5000,
- forcePrefix - set the prefix for "force Sixpack experiment" GET parameter; default:
sixpack-force-.
Additionally CookieSession adds another option:
- cookiePrefix - set the prefix for cookie (not applicable when clientId is set); default:
sixpack,
If you'd like to force the Sixpack server to return a specific alternative for development or testing, you can do so by passing a query parameter prefixed with <forcePrefix> option (see above) to that page being tested.
If you're using default configuration this would look like this:
http://example.com/?sixpack-force-<experiment name>=<alternative name>
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git add -p+git commit -m 'Added some feature'; never usegit commit -a) - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
sixpack-php is released under the BSD 2-Clause License.