PHPackages                             derian-cordoba/laravel-ab-testing - 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. derian-cordoba/laravel-ab-testing

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

derian-cordoba/laravel-ab-testing
=================================

AB testing package for laravel

1.3.0(1mo ago)21MITPHPPHP ^8.3 || ^8.4CI passing

Since Jun 11Pushed 1mo agoCompare

[ Source](https://github.com/derian-cordoba/laravel-ab-testing)[ Packagist](https://packagist.org/packages/derian-cordoba/laravel-ab-testing)[ RSS](/packages/derian-cordoba-laravel-ab-testing/feed)WikiDiscussions main Synced 1w ago

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

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

[](#laravel-ab-testing)

Standalone experimentation primitives for Laravel: typed experiments, deterministic bucketing, reusable metrics, Bayesian and frequentist analysis, and a package architecture that can grow into a full experimentation platform.

This package is intentionally not a thin feature-flag helper. It is designed around real experimentation concerns: stable assignment units, explicit control and traffic allocation, reusable metrics, sample-ratio mismatch detection, and normalized experiment definitions that can be consumed by both code-defined and runtime-defined workflows.

[![A/B Testing dashboard screenshot](docs/resources/ab-testing-dashboard-screenshot.png)](docs/resources/ab-testing-dashboard-screenshot.png)

Contents
--------

[](#contents)

- [Current status](#current-status)
- [Why this package](#why-this-package)
- [Installation](#installation)
- [Quick start](#quick-start)
- [Defining units](#defining-units)
- [Defining metrics](#defining-metrics)
- [Defining variants](#defining-variants)
- [Defining experiments](#defining-experiments)
- [Registering experiments](#registering-experiments)
- [Blade directives](#blade-directives)
- [Resolving variants](#resolving-variants)
- [Tracking metrics](#tracking-metrics)
- [Real-world request flow](#real-world-request-flow)
- [Dashboard](#dashboard)
- [Management API](#management-api)
- [Discovery and caching](#discovery-and-caching)
- [Running statistical analysis](#running-statistical-analysis)
- [Feature flags](#feature-flags)
- [Architecture](#architecture)
- [Production integration](#production-integration)
    - [Storage driver](#storage-driver)
- [Testing](#testing)
- [Current limitations](#current-limitations)
- [Contributing](#contributing)
- [License](#license)

Current status
--------------

[](#current-status)

This repository already includes the foundational engine and several important runtime pieces:

- Attribute-based experiment definitions via `#[AsExperiment]`, `#[AsMetric]`, `#[AsUnit]`, and related attributes
- Typed variant enums with explicit control and weight declarations
- Deterministic bucketing with an SHA-256 strategy
- Assignment persistence behind repository contracts
- A resolution pipeline for eligibility, traffic checks, sticky assignment, and layer exclusion
- Database-backed event recording for exposures and metrics
- Incremental rollups over raw events for dashboard reads
- Bayesian and frequentist analysis engines
- Sample-ratio mismatch detection
- A built-in Livewire dashboard with experiment overview, detail pages, controls, audit trail, and results tables
- Experiment registration from configuration and optional discovery

Some larger platform pieces are still intentionally not presented as finished:

- Runtime-defined experiment authoring in the dashboard
- Full feature-flag registry and runtime integration

The README below focuses on what exists today and shows how to use the package honestly in its current form.

Why this package
----------------

[](#why-this-package)

Most Laravel A/B testing packages stop at "split users into two buckets and count conversions". This package is aiming at a stricter model:

- Experiments are typed PHP classes, not magic strings
- Variants are backed enums, not loose arrays
- Assignment is deterministic and sticky
- Assignment and exposure are different events
- Metrics are reusable definitions with explicit roles
- Analysis is unit-based, not raw-event-based
- Frequentist and Bayesian results can live side by side
- The engine consumes a normalized `ExperimentDefinition`, so code-defined and runtime-defined experiments can converge on the same core

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

[](#installation)

Install the package with Composer:

```
composer require derian-cordoba/laravel-ab-testing
```

Publish the configuration file:

```
php artisan vendor:publish --tag=ab-testing-config
```

Run the migrations:

```
php artisan migrate
```

If you want to customize the package dashboard views, publish them:

```
php artisan vendor:publish --tag=ab-testing-dashboard-views
```

The package supports Laravel package discovery, so you should not need to register the service provider manually.

### Requirements

[](#requirements)

- PHP `^8.4`
- Laravel components `illuminate/support ^13.0`
- `illuminate/console ^13.0`

Quick start
-----------

[](#quick-start)

The package revolves around four structural definitions:

1. A unit type that can be bucketed
2. A reusable metric
3. A backed enum of variants
4. An experiment class that ties them together

Here is a complete minimal example.

### 1. Define the assignment unit

[](#1-define-the-assignment-unit)

```
