PHP Experiments is a library that lets you run A/B and split tests
Clone or download
tsteur Merge pull request #7 from innocraft/paqvarinit
Make sure _paq variable exists
Latest commit 32333c6 Dec 18, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs rename split test variation to url redirect variation Dec 20, 2016
examples mention date time can be used Dec 20, 2016
src Make sure _paq variable exists Dec 17, 2018
tests fix test Dec 17, 2018
.gitignore first commit Dec 20, 2016
.scrutinizer.yml Update documentation and examples (#4) Dec 21, 2016
.travis.yml Make travis work Dec 20, 2016
LICENSE first commit Dec 20, 2016 Piwik => Matomo Jan 10, 2018
composer.json Make travis work Dec 20, 2016
phpunit.xml first commit Dec 20, 2016

PHP Experiments is an A/B Test and Split Test library

Code Status

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version License


PHP Experiments is built for A/B and Split Testing for Matomo Analytics but can be used in any PHP project. Matomo (formerly Piwik) is the leading open source web analytics platform used on over 1 million websites and apps in over 150 countries. InnoCraft is the company of the makers of Matomo Analytics.


  • Easily create and run A/B tests and split tests.
  • Experiment traffic allocation: For example configure that only 80% of all users should participate in an experiment.
  • Variation traffic allocation: For example allocate more traffic to some specific variations, giving other variations less traffic.
  • When a user enters an experiment for the first time, a variation will be chosen randomly. On all subsequent requests the same variation will be activated.
  • Possibility to force a specific variation instead of choosing it randomly.
  • To ensure a user always gets to see the same variation, the name of the activated variation is stored in a cookie, a custom storage can be configured.
  • Easy to use with plain arrays and easily extensible and customizable (custom storage, filters and variations can be defined).
  • Tested with unit tests.
  • No dependencies, lightweight, simple.


See examples directory for various examples.

Running an A/B test might be as easy as:

$variations = [['name' => 'green'], ['name' => 'blue']];
$experiment = new Experiment('experimentName', $variations);
$activated = $experiment->getActivatedVariation();

echo $activated->getName();

Running a split URL test can be as easy as:

$variations = [
    ['name' => 'layout1', 'url' => '/layout1'], 
    ['name' => 'layout2', 'url' => '/layout2']
$experiment = new Experiment('experimentName', $variations);
$activated = $experiment->getActivatedVariation();

// redirects to either URL or does nothing if the original version was activated


  • PHP 5.5.9 or greater


To get the latest version, require the library using Composer:

$ composer require innocraft/php-experiments

Instead, you may manually update your require block and run composer update if you so choose:

    "require": {
        "innocraft/php-experiments": "^1.0"


PHP Experiments is released under the LGPL v3 license, see LICENSE.


Docs generation

To update the documentation within the docs directory execute the following commands

  • cd docs
  • composer install (only needed once)
  • ./