PHPackages                             folez/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. folez/laravel-ab

Active

folez/laravel-ab
================

00PHP

Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersionsUsed By (0)

[![Build](https://github.com/folez/laravel-ab/actions/workflows/build.yml/badge.svg)](https://github.com/folez/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 copied and updated from:

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

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

[](#installation)

This package can be used in Laravel 9 or higher.

You can install the package via composer:

```
composer require folez/laravel-ab
```

Config
------

[](#config)

After installation publish the config file:

```
php artisan vendor:publish --provider="folez\LaravelAB\Providers\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)

- [Filipe Gonçalves](https://github.com/Filipe07)
- [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.

###  Health Score

10

—

LowBetter than 0% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity8

Early-stage or recently created project

 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

Maintainers

![](https://www.gravatar.com/avatar/8f489e12f23c4d049c326e939a312178c31eae6dfa43fa54cf71e1eb43a7d57a?d=identicon)[folez](/maintainers/folez)

---

Top Contributors

[![AndreyDemenenko](https://avatars.githubusercontent.com/u/14270217?v=4)](https://github.com/AndreyDemenenko "AndreyDemenenko (3 commits)")

### Embed Badge

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

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

PHPackages © 2026

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