Download the PHP package derian-cordoba/laravel-ab-testing without Composer

On this page you can find all versions of the php package derian-cordoba/laravel-ab-testing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-ab-testing

Laravel A/B 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.

Contents

Current status

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

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

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

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:

Installation

Install the package with Composer:

Publish the configuration file:

Run the migrations:

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

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

Requirements

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

2. Define the metric

3. Define the variants

4. Define the experiment

5. Register the experiment

Add it to config/ab-testing.php:

6. Resolve the variant

7. Track the conversion

Defining units

Every experiment and metric event is anchored to a unit that implements ABTests\Contracts\Bucketable.

A unit must provide:

Use #[AsUnit] to give each unit type a stable storage key:

The key argument accepts either:

That normalization follows the same semantics as Laravel's enum_value() helper.

Defining metrics

Metrics are reusable definitions. An experiment does not describe how a conversion is measured; it references one or more metrics and assigns them roles.

Available metric attributes:

Example:

The #[AsMetric] attribute describes the metric itself:

When valueFromProperty is set, the base Metric::valueOf() reads that property from the event's payload automatically and casts it to float. Override valueOf() only when the derivation requires custom logic beyond reading a single property:

Metric roles

Raw metric keys are also supported

The runtime tracking layer accepts either:

That matters because the core engine is designed to support both code-defined and runtime-defined experiments.

Defining variants

Variants must be backed enums that implement ABTests\Contracts\Variant. The easiest way to satisfy the contract is to use the ABTests\Concerns\IsVariant trait.

Rules enforced by the package:

Example with three arms:

The package preserves the original enum case on resolution, so downstream application code can use match exhaustively and stay type-safe.

Defining experiments

Use #[AsExperiment] on a class extending ABTests\Experiment.

Experiment structure

The attribute captures the structural parts of an experiment:

These are treated as code-owned structure. In the intended architecture, operational state such as running, paused, and traffic percentage belongs to persistence and dashboard workflows, not the class definition itself.

Audience targeting

Override audience() when the experiment should only apply to a segment:

The current Segment API supports conjunctions of criteria and operators such as:

Registering experiments

The package boots an ExperimentRegistry from configuration.

In config/ab-testing.php:

If an experiment cannot be read at boot, the service provider logs the failure instead of crashing the whole app.

Blade directives

The package registers four Blade directives for conditional rendering without writing resolver boilerplate.

The current unit is resolved at render time using Auth::user() when the authenticated user implements Bucketable, or a session-keyed GenericUnit for unauthenticated visitors.

Resolving variants

The main entry point is ABTests\Experiments.

Resolution goes through a pipeline with the following responsibilities:

When a variant is successfully resolved, the package records an exposure event through the configured EventSink.

Attribute-driven resolution via middleware

Attach #[ResolvesExperiment] to a controller method and add ->middleware('ab-testing.resolve') to the route. The middleware resolves the variant, records the exposure, and injects the typed enum directly into the method:

The middleware resolves the unit from the first Bucketable route parameter it finds, falling back to Auth::user() if the user implements Bucketable. If neither is available the method receives null.

Null return values

variant() returns null when the unit should not receive the experiment at all. Typical reasons include:

That is intentional. "Not eligible" is not the same thing as "assigned to control".

Tracking metrics

Track a metric for a unit with either the facade or the per-unit resolver:

You can also pass a raw metric key:

For continuous metrics:

Tracking behavior:

Real-world request flow

Below is a realistic end-to-end checkout flow showing where variant resolution and metric tracking usually belong in an application.

Controller example

Practical guidance

A good mental model

One safe way to think about the package is:

If those two calls happen in the correct places, the rest of the package architecture stays coherent.

Dashboard

The package ships with a Livewire dashboard mounted at /ab-testing by default. It is intended to be the operational surface for experiment state:

Dashboard access

The dashboard route prefix, middleware stack, and viewer gate are configured in config/ab-testing.php:

Define the gate in your application if you want to restrict access:

If the configured gate does not exist, the package middleware falls back to whatever access rules your configured dashboard middleware already enforces.

What the dashboard reads

The dashboard does not scan raw event tables on every request. It reads pre-aggregated rows from ab_testing_rollups through ResultsService, then runs the analysis layer on those summaries.

That separation matters:

Making results appear

To see data in the dashboard:

  1. Run the package migrations.
  2. Register your experiments in config/ab-testing.php.
  3. Ensure each experiment has an operational state row in ab_testing_experiments.
  4. Put the experiment into running state, either through the dashboard or your own setup code.
  5. Generate exposures and metric events by resolving variants and tracking outcomes.
  6. Let the scheduled rollup run or use the dashboard's Refresh Data control.

Rollup scheduling

When ab-testing.dashboard.auto_schedule_rollups is enabled, the package registers RefreshRollupsJob with Laravel's scheduler automatically. You still need a normal scheduler/queue setup in the host app:

Or your usual production scheduler:

For local development, the dashboard can also trigger a manual per-experiment refresh so you do not have to wait for the next scheduled cycle.

Management API

The package ships a versioned REST API for managing experiments programmatically. It covers the full experiment lifecycle — create, configure variants, start, pause, resume, stop, archive — as well as results polling and CI/CD verdict endpoints.

All endpoints require the configured vendor media type in the Accept header:

Requests that omit it or send a wildcard are rejected before reaching any controller. Every response carries the same value as Content-Type. The vendor type is read from ab-testing.api.v1.accept_type in your config so changing it propagates everywhere without touching controller code.

See the full reference in docs/api.md for:

Discovery and caching

The package includes an ab:cache Artisan command:

When discovery is enabled in config, the command scans configured paths for PHP classes, extracts class names without executing the files, reads #[AsExperiment] definitions, and registers them in the runtime registry.

Example config:

This is useful when you want explicit deployment-time registration without manually maintaining a long config list.

Running statistical analysis

The analysis layer is already present as a framework-agnostic service. It expects pre-aggregated unit-level summaries rather than raw events.

What the analysis layer does

Statistical defaults

By default, experiments use:

These defaults come from AnalysisConfiguration::default().

Feature flags

The package already contains a FeatureFlag base class and #[AsFeatureFlag] attribute:

Registering feature flags

Add flags to config/ab-testing.php under feature_flags.register:

Auto-discovery works the same way as experiments: enable discovery.enabled and point discovery.paths at the directory containing your flag classes.

Stale flag detection

A flag is considered stale when it is still enabled but has not been modified for longer than the configured threshold. Stale flags surface with an amber badge on the feature flags dashboard page.

Architecture

The package follows a layered design:

Key contracts and abstractions:

Default bindings:

The storage driver is configurable; the in-memory alternatives are available for tests and local development without a database connection (see Storage driver below).

Production integration

The package ships with a full Eloquent database layer enabled by default. Running the migrations is the only step needed to go from zero to a working persistent store.

Storage driver

The storage driver controls which repository implementations are bound. Set it in config/ab-testing.php or via environment variable:

Driver Assignment repository State repository When to use
database (default) DatabaseAssignmentRepository DatabaseExperimentStateRepository Production and staging
in_memory InMemoryAssignmentRepository AlwaysRunningExperimentStateRepository Unit tests, local dev without a DB

Migrations

The package loads its migrations automatically. If you prefer to publish them to your application's database/migrations directory:

The package migrations create these tables:

ab_testing_experiments — mutable operational state driven from the dashboard (status, traffic percentage, kill switch). One row per experiment key.

ab_testing_assignments — sticky, deterministic bucketing. One row per (experiment_key, unit_type, unit_key) triple. The composite primary key enforces idempotency: the first write wins and duplicates are silently discarded.

ab_testing_events — append-only exposure and metric event log.

ab_testing_rollups — pre-aggregated experiment summaries used by the dashboard and analysis layer.

ab_testing_guardrail_breaches — breach records emitted when a guardrail crosses its threshold.

ab_testing_audit_log — operational audit trail for dashboard actions.

ab_testing_feature_flag_states — persisted state for feature flags; UI surface is still limited.

ab_testing_experiments.target_sample_size — nullable progress target shown in the dashboard when set.

Creating experiment state rows

The DatabaseExperimentStateRepository looks up a row in ab_testing_experiments by key. If no row exists, the resolver treats the experiment as not running and returns null. You need to insert a row before an experiment can go live, either via the dashboard or your own bootstrap code:

Event sink

When AB_TESTING_DRIVER=database, the package binds DatabaseEventSink automatically and flushes its buffered events at the end of each request. In-memory mode intentionally keeps the no-op sink:

Production checklist

What not to do

Testing

Run the full test suite:

Or directly with PHPUnit:

Static analysis:

The repository also includes a GitHub Actions workflow for tests.

Current limitations

This package is not pretending to be more finished than it is. Before adopting it in production, keep these points in mind:

If you want to evaluate the package today, the strongest implemented path is:

Contributing

Contributions are welcome, especially around:

If you open a pull request, keep the current package direction in mind:

License

This package is open-sourced under the MIT license.


All versions of laravel-ab-testing with dependencies

PHP Build Version
Package Version
Requires illuminate/console Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0
livewire/livewire Version ^4.0
php Version ^8.3 || ^8.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package derian-cordoba/laravel-ab-testing contains the following files

Loading the files please wait ...