PHPackages                             jamesblackwell/laravel-experiments - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jamesblackwell/laravel-experiments

Abandoned → [jamesblackwell/laravel-ab-testing](/?search=jamesblackwell%2Flaravel-ab-testing)Library[Utility &amp; Helpers](/categories/utility)

jamesblackwell/laravel-experiments
==================================

A server-side A/B testing tool for Laravel.

061PHP

Since Apr 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jamesblackwell/laravel-experiments)[ Packagist](https://packagist.org/packages/jamesblackwell/laravel-experiments)[ RSS](/packages/jamesblackwell-laravel-experiments/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

**Abandoned: Use **

Laravel 5.2 A/B Testing
=======================

[](#laravel-52-ab-testing)

A server-side A/B testing tool for Laravel, a great free alternative for services such as optimizely. Use A/B testing to figure out which content works, and which doesn't.

This tool allows you to experiment with different variations of your website and tracks what the difference in engagement or reached goals is between them. Whenever you ask the A/B testing class for the current experiment, it will select the next experiment that has the least visits so that every experiment is tested equally. When there is an active experiment going on, it will start tracking engagement (click a different link, or submitting a form) and check if certain defined goals are reached. These goals are generally urls or routes, but can also be triggered manually.

Installation
------------

[](#installation)

Require the package

composer require jamesblackwell/laravel-experiments

Add the service provider in `app/config/app.php`:

```
'Jamesblackwell\AB\TesterServiceProvider',

```

Register the AB alias:

```
'AB'           => 'Jamesblackwell\AB\Facades\AB',

```

Configuration
-------------

[](#configuration)

Publish the included configuration file:

```
php artisan config:publish jamesblackwell/ab

```

Next, edit the `config/packages/jamesblackwell/ab/config.php` file. The following configuration options are available:

### Database Connection

[](#database-connection)

This is your Laravel database connection that is used to store the A/B testing data. This is handy when you want to store the A/B testing data in a different database. When empty, it will use your default database connection.

```
'connection' => 'mysql',

```

### Experiments

[](#experiments)

These are your A/B experiments. These are unique identifiers that you can use in your code or views to decide which version you should be showing.

```
'experiments' => [
    'big-logo',
    'small-buttons',
    'short-form'
],

```

### Goals

[](#goals)

Without goals, each experiment will track the number of visitors that saw the experiment and detect engagement. Additionally, you can define certain goals that you want to reach with your experiments. If, your main goal is for your visitors to buy your product or contact you for more information, and you have specific routes set up for both of these pages, your goals could look like this:

```
'goals' => [
    'pricing/order',
    'contact'
]

```

Your goals can be relative urls, named routes or can be triggered manually.

Preparing the A/B test database
-------------------------------

[](#preparing-the-ab-test-database)

Once you have selected your database connection, use the included install command to prepare the required tables:

```
php artisan ab:install

```

The database structure is small and lightweight, so it will not impact your application.

Usage
-----

[](#usage)

After you have defined your experiments and goals, you can start designing your A/B tests. All your visitors will be given the next experiment that has the least visits. You can request the current experiment identifier with the `AB::experiment()` method. For example, if you have defined the following experiments `['a', 'b', 'c']`, your view could look like this:

```
@if (AB::experiment('a'))

@elseif (AB::experiment('b'))
    Brand name

@elseif (AB::experiment('c'))

@else
    // Original or default value
    // This maybe appears when experiment has inactive
@endif

```

Once the visitor is assigned to an experiment, his next clicks are automatically tracked to see if he is engaging with your website or completing certain goals. These goals are relative urls or named routes, and will be marked as completed when a visitor visits that url during an experiment.

**NOTE**: Visitors are only tracked if you are conducting an experiment. Only when you ask the current `AB::experiment()`, it will assign an experiment to that user using the current Laravel session.

### Adding new experiments

[](#adding-new-experiments)

If you want to add new experiments, it may be best to clear the existing A/B testing data with this command:

```
php artisan ab:flush

```

If you don't flush your existing experimental data, all new visitors will see the new experiment first until it catches up with the pageviews of the old experiments.

Reports
-------

[](#reports)

A/B testing reports are available through an artisan command:

```
php artisan ab:report

```

This will generate a simple output containing the results for each experiment and their goals.

```
+------------+----------+----------------+---------------+---------------+---------------+
| Experiment | Visitors |     Engagement |           Buy |       Contact |       Pricing |
+------------+----------+----------------+---------------+---------------+---------------+
|          a |  173,074 | 6.0 % (10,363) | 1.3 % (2,249) | 4.8 % (8,307) | 5.3 % (9,172) |
|          b |  173,073 |  5.1 % (8,826) | 1.1 % (1,903) | 3.5 % (6,057) | 3.9 % (6,749) |
|          c |  173,073 |  5.0 % (8,653) | 1.0 % (1,730) | 1.3 % (5,538) | 3.2 % (5,538) |
+------------+----------+----------------+---------------+---------------+---------------+

```

You can also export these reports to .csv format using this command:

```
php artisan ab:export /path/to/file.csv

```

If you run that command without a filepath, it will write it to the console.

Advanced
--------

[](#advanced)

**AB::pageview()**

Used to manually trigger an pageview.

**AB::interact()**

Used to manually trigger an interaction which results in engagement.

**AB::complete($goal)**

Used to manually trigger goals. Useful when you want to track goals that are not linked to urls or routes.

**AB::getExperiments()**

Get the list of experiments.

**AB::getGoals()**

Get the list of goals.

**AB::hasExperiments()**

Return true if has more than 1 experiment into table "experiments".

**AB::currentExperiment()**

Return the name of the current session experiment.

Advanced
--------

[](#advanced-1)

Edited and exported to Laravel 5.1 by @rafelsanso

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

---

Top Contributors

[![jamesblackwell](https://avatars.githubusercontent.com/u/1156154?v=4)](https://github.com/jamesblackwell "jamesblackwell (14 commits)")

### Embed Badge

![Health badge](/badges/jamesblackwell-laravel-experiments/health.svg)

```
[![Health](https://phpackages.com/badges/jamesblackwell-laravel-experiments/health.svg)](https://phpackages.com/packages/jamesblackwell-laravel-experiments)
```

###  Alternatives

[fntneves/laravel-transactional-events

Transaction-aware Event Dispatcher for Laravel

3202.6M2](/packages/fntneves-laravel-transactional-events)[ipinfo/ipinfo

The official PHP library for IPinfo, the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier and IP type data sets. Visit our developer docs at https://ipinfo.io/developers.

2891.2M11](/packages/ipinfo-ipinfo)[craftcms/plugin-installer

Craft CMS Plugin Installer

283.3M4](/packages/craftcms-plugin-installer)[typo3/cms-recordlist

TYPO3 CMS Recordlist - Lists database records in the TYPO3 backend module (Web&gt;List).

178.0M48](/packages/typo3-cms-recordlist)[broadway/uuid-generator

UUID generator for broadway/broadway.

202.1M11](/packages/broadway-uuid-generator)[kohkimakimoto/background-process

A minimum library to run background processes asynchronously.

361.4k](/packages/kohkimakimoto-background-process)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
