PHPackages                             filipe07/laravel-ab - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. filipe07/laravel-ab

ActiveLibrary[Testing &amp; Quality](/categories/testing)

filipe07/laravel-ab
===================

Laravel A/B experiment testing tool

1.0.3(10mo ago)161.3k↓45.9%5MITPHPPHP ^7.2 | ^8.0CI passing

Since Apr 4Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/Filipe07/laravel-ab)[ Packagist](https://packagist.org/packages/filipe07/laravel-ab)[ Docs](https://github.com/filipe07/laravel-ab)[ RSS](/packages/filipe07-laravel-ab/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (6)Versions (5)Used By (0)

[![Build](https://github.com/filipe07/laravel-ab/actions/workflows/build.yml/badge.svg)](https://github.com/filipe07/laravel-ab/actions/workflows/build.yml/badge.svg)[![Release](https://camo.githubusercontent.com/50dd2673980de4a0e85941f039c4f4c6fb2be8c3447ee40e476b5e38bf5c8d82/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f52656c656173652d312e302e302d677265656e)](https://camo.githubusercontent.com/50dd2673980de4a0e85941f039c4f4c6fb2be8c3447ee40e476b5e38bf5c8d82/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f52656c656173652d312e302e302d677265656e)

---

######  [![](https://camo.githubusercontent.com/42de242d9a3ef51acd6cb4ca83997f5a2c889b47334c014c92339d23122b2685/68747470733a2f2f692e6962622e636f2f687937666a4d472f4c61726176656c2d41422e706e67)](https://camo.githubusercontent.com/42de242d9a3ef51acd6cb4ca83997f5a2c889b47334c014c92339d23122b2685/68747470733a2f2f692e6962622e636f2f687937666a4d472f4c61726176656c2d41422e706e67)

[](#----)

This package helps you to find out which content works on your site and which doesn't.

It allows you to create experiments and goals. The visitor will receive randomly the next experiment and you can customize your site to that experiment. The view and the goal conversion will be tracked and you can view the results in a report.

This package is very inspired and a mix of two other packages:

- [ben182/laravel-ab](https://github.com/ben182/laravel-ab)
- [mfjordvald/laravel-ab](https://github.com/mfjordvald/laravel-ab)

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

[](#installation)

This package can be used in Laravel 8 or higher.

You can install the package via composer:

```
composer require filipe07/laravel-ab
```

Config
------

[](#config)

After installation publish the config file:

```
php artisan vendor:publish --provider="AbTesting\AbTestingServiceProvider"
```

You can define your experiments and goals in there.

Finally, run the newly added migration

```
php artisan migrate
```

Two new migrations should be added.

Usage
-----

[](#usage)

### Variants

[](#variants)

```
@if (AbTesting::isVariant('logo-big'))

@elseif (AbTesting::isVariant('logo-grayscale'))

@elseif (AbTesting::isVariant('brand-name'))

    Brand name

@endif
```

That's the most basic usage of the package. You don't have to initialize anything. The package handles everything for you if you call `isVariant`

Alternatively you can use a custom blade if statement:

```
@ab('logo-big')

@elseab('logo-grayscale')

@elseab('brand-name')

    Brand name

@endab
```

This will work exactly the same way.

If you don't want to make any continual rendering you can call

```
AbTesting::pageView()
```

directly and trigger a new page view with a random variant. This function will also be called from `isVarian`.

Under the hood a new session item will keep track of the current variant. A session will only get one variant and only trigger one page view.

You can grab the current variant with:

```
// get the underlying model
AbTesting::getVariant()

// get the variant name
AbTesting::getVariant()->name

// get the visitor count
AbTesting::getVariant()->visitors
```

Alternatively there is a request helper for you:

```
public function index(Request $request) {
    // the same as 'AbTesting::getVariant()'
    $request->abVariant()
}
```

### Goals

[](#goals)

To complete a goal simply call:

```
AbTesting::completeGoal('signup')
```

The function will increment the conversion of the goal assigned to the active variant. If there isn't an active variant running for the session one will be created. You can only trigger a goal conversion once per session. This will be prevented with another session item. The function returns the underlying goal model.

To get all completed goals for the current session:

```
AbTesting::getCompletedGoals()
```

### Persisting visitor data

[](#persisting-visitor-data)

When used in the above way the visitor data is stored in session data attached to the user. In some cases you might want to trigger a goal completion in an asynchronous way and the users session won't be available. To avoid getting bad data by registering the goal completion under a new variant you can persist the visitor data in the database.

To do this you pass a user identifier to the pageview function.

```
AbTesting::pageview($identifier)
```

In your asynchronous request you can then provide the same idenfier to the completeGoals function.

```
AbTesting::completeGoal('payment-completed', $identifier)
```

### Report

[](#report)

To get a report of the page views, completed goals and conversion call the report command:

```
php artisan ab:report
```

This prints something like this:

```
+---------------+----------+-------------+
| Variant       | Visitors | Goal signup |
+---------------+----------+-------------+
| big-logo      | 2        | 1 (50%)     |
| small-buttons | 1        | 0 (0%)      |
+---------------+----------+-------------+

```

### Reset

[](#reset)

To reset all your visitors and goal completions call the reset command:

```
php artisan ab:reset
```

### Events

[](#events)

In addition you can hook into two events:

- `VariantNewVisitor` gets triggered once an variant gets assigned to a new visitor. You can grab the variant and visitor instance as properties of the event.
- `GoalCompleted` gets triggered once a goal is completed. You can grab the goal as a property of the event.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Benjamin Bortels](https://github.com/ben182)
- [Martin Fjordvald](https://github.com/mfjordvald)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance54

Moderate activity, may be stable

Popularity34

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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.

###  Release Activity

Cadence

Every ~413 days

Total

4

Last Release

311d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13201159?v=4)[Filipe Gonçalves](/maintainers/Filipe07)[@Filipe07](https://github.com/Filipe07)

---

Top Contributors

[![Filipe07](https://avatars.githubusercontent.com/u/13201159?v=4)](https://github.com/Filipe07 "Filipe07 (1 commits)")[![JoelInfraspeak](https://avatars.githubusercontent.com/u/107863636?v=4)](https://github.com/JoelInfraspeak "JoelInfraspeak (1 commits)")[![mariorocha](https://avatars.githubusercontent.com/u/63719082?v=4)](https://github.com/mariorocha "mariorocha (1 commits)")

---

Tags

phplaravellaravel-packageab-testinglaravel-5-packageben182filipe07mfjordvald

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/filipe07-laravel-ab/health.svg)

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

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.5k55.4M8.4k](/packages/larastan-larastan)[ben182/laravel-ab

Laravel A/B experiment testing tool

10913.8k](/packages/ben182-laravel-ab)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

15118.7k4](/packages/calebdw-larastan)

PHPackages © 2026

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