PHPackages                             apurbajnu/abtest - 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. apurbajnu/abtest

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

apurbajnu/abtest
================

Laravel 8 AB testing package

v1.1(3y ago)1633MITPHPPHP ^7.4 || ^8.0

Since Aug 4Pushed 3y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

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

[](#----)

[![Latest Version](https://camo.githubusercontent.com/c3ce61db6a98f1a6d141a4fc3b3f83c182674ba8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f62656e3138322f6c61726176656c2d61622e7376673f7374796c653d666c61742d737175617265)](https://github.com/ben182/laravel-ab/releases)[![Build Status](https://camo.githubusercontent.com/7994c56ad88fb3e839360835571cc670d88af2e2/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f62656e3138322f6c61726176656c2d61622f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/ben182/laravel-ab)[![Quality Score](https://camo.githubusercontent.com/88e5e8e14c12f93518fa07a025a15893ae8772e4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f62656e3138322f6c61726176656c2d61622e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/ben182/laravel-ab)[![Code Coverage](https://camo.githubusercontent.com/de896bb05aa6d6224d2c1e7be81c36b18895128d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f62656e3138322f6c61726176656c2d61622f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ben182/laravel-ab/?branch=master)

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.

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

[](#installation)

This package is clone of ben182/laravel-ab &amp; Compatiable with Laravel 8 This package compatiable with Laravel 8.

You can install the package via composer:

```
composer require apurbajnu/abtest
```

Config
------

[](#config)

After installation publish the config file:

```
php artisan vendor:publish --provider="Apurbajnu\abtest\AbtestServiceProvider"
```

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)

### Experiments

[](#experiments)

```
@if (Abtest::isExperiment('logo-big'))

@elseif (Abtest::isExperiment('logo-grayscale'))

@elseif (Abtest::isExperiment('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 `isExperiment`

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

```
Abtest::pageView()
```

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

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

You can grab the current experiment with:

```
// get the underlying model
Abtest::getExperiment()

// get the experiment name
Abtest::getExperiment()->name

// get the visitor count
Abtest::getExperiment()->visitors
```

Alternatively there is a request helper for you:

```
public function index(Request $request) {
    // the same as 'Abtest::getExperiment()'
    $request->abExperiment()
}
```

### Goals

[](#goals)

To complete a goal simply call:

```
Abtest::completeGoal('signup')
```

The function will increment the conversion of the goal assigned to the active experiment. If there isn't an active experiment 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:

```
Abtest::getCompletedGoals()
```

### Bots and crawlers

[](#bots-and-crawlers)

The package can try to ignore bots and crawlers from registering pageviews. Just enable the `ignore_crawlers` option in the config.

### 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:

```
+---------------+----------+-------------+
| Experiment    | 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:

- `ExperimentNewVisitor` gets triggered once an experiment gets assigned to a new visitor. You can grab the experiment as a property 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)
- [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

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1374d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0d318cae8c5752c6e3937e3233e2262cb3480a83d821ac4fe6bf5aef4ab9878c?d=identicon)[apurbajnu](/maintainers/apurbajnu)

---

Top Contributors

[![apurbajnu](https://avatars.githubusercontent.com/u/9669037?v=4)](https://github.com/apurbajnu "apurbajnu (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/apurbajnu-abtest/health.svg)

```
[![Health](https://phpackages.com/badges/apurbajnu-abtest/health.svg)](https://phpackages.com/packages/apurbajnu-abtest)
```

###  Alternatives

[wireui/wireui

TallStack components

1.8k1.3M16](/packages/wireui-wireui)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21147.4k](/packages/ramonrietdijk-livewire-tables)

PHPackages © 2026

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