Skip to content

snpy/sixpack-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sixpack

PHP client library for SeatGeak's Sixpack ab testing framework.

Installation

  1. Install Composer.
  2. In the root of your project install sixpack via composer require snpy/sixpack-php.
  3. If computer autoloader is not already included put require 'vendor/autoload.php'; at the top of you script.

Usage

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>

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git add -p + git commit -m 'Added some feature'; never use git commit -a)
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

sixpack-php is released under the BSD 2-Clause License.

About

PHP client library for SeatGeek's Sixpack A/B testing framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%