• Stars
    star
    288
  • Rank 143,818 (Top 3 %)
  • Language
    PHP
  • Created over 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A server-side A/B testing tool for Laravel.

Laravel A/B Testing

Build Status Coverage Status

A server-side A/B testing tool for Laravel, a great free alternative for services such as optimizely. Use A/B testing to figure out which content works, and which doesn't.

This tool allows you to experiment with different variations of your website and tracks what the difference in engagement or reached goals is between them. Whenever you ask the A/B testing class for the current experiment, it will select the next experiment that has the least visits so that every experiment is tested equally. When there is an active experiment going on, it will start tracking engagement (click a different link, or submitting a form) and check if certain defined goals are reached. These goals are generally urls or routes, but can also be triggered manually.

Installation

Install using composer:

composer require jenssegers/ab

Add the service provider in app/config/app.php:

'Jenssegers\AB\TesterServiceProvider',

Register the AB alias:

'AB'           => 'Jenssegers\AB\Facades\AB',

Configuration

Publish the included configuration file:

php artisan config:publish jenssegers/ab

Next, edit the config/packages/jenssegers/ab/config.php file. The following configuration options are available:

Database Connection

This is your Laravel database connection that is used to store the A/B testing data. This is handy when you want to store the A/B testing data in a different database. When empty, it will use your default database connection.

'connection' => 'mysql',

Experiments

These are your A/B experiments. These are unique identifiers that you can use in your code or views to decide which version you should be showing.

'experiments' => [
    'big-logo',
    'small-buttons',
    'short-form'
],

Goals

Without goals, each experiment will track the number of visitors that saw the experiment and detect engagement. Additionally, you can define certain goals that you want to reach with your experiments. If, your main goal is for your visitors to buy your product or contact you for more information, and you have specific routes set up for both of these pages, your goals could look like this:

'goals' => [
    'pricing/order',
    'contact'
]

Your goals can be relative urls, named routes or can be triggered manually.

Preparing the A/B test database

Once you have selected your database connection, use the included install command to prepare the required tables:

php artisan ab:install

The database structure is small and lightweight, so it will not impact your application.

Usage

After you have defined your experiments and goals, you can start designing your A/B tests. All your visitors will be given the next experiment that has the least visits. You can request the current experiment identifier with the AB::experiment() method. For example, if you have defined the following experiments ['a', 'b', 'c'], your view could look like this:

@if (AB::experiment('a'))
    <div class="logo-big"></div>

@elseif (AB::experiment('b'))
    <h1>Brand name</h1>

@elseif (AB::experiment('c'))
    <div class="logo-greyscale"></div>

@endif

Once the visitor is assigned to an experiment, his next clicks are automatically tracked to see if he is engaging with your website or completing certain goals. These goals are relative urls or named routes, and will be marked as completed when a visitor visits that url during an experiment.

NOTE: Visitors are only tracked if you are conducting an experiment. Only when you ask the current AB::experiment(), it will assign an experiment to that user using the current Laravel session.

Adding new experiments

If you want to add new experiments, it may be best to clear the existing A/B testing data with this command:

php artisan ab:flush

If you don't flush your existing experimental data, all new visitors will see the new experiment first until it catches up with the pageviews of the old experiments.

Reports

A/B testing reports are available through an artisan command:

php artisan ab:report

This will generate a simple output containing the results for each experiment and their goals.

+------------+----------+----------------+---------------+---------------+---------------+
| Experiment | Visitors |     Engagement |           Buy |       Contact |       Pricing |
+------------+----------+----------------+---------------+---------------+---------------+
|          a |  173,074 | 6.0 % (10,363) | 1.3 % (2,249) | 4.8 % (8,307) | 5.3 % (9,172) |
|          b |  173,073 |  5.1 % (8,826) | 1.1 % (1,903) | 3.5 % (6,057) | 3.9 % (6,749) |
|          c |  173,073 |  5.0 % (8,653) | 1.0 % (1,730) | 1.3 % (5,538) | 3.2 % (5,538) |
+------------+----------+----------------+---------------+---------------+---------------+

You can also export these reports to .csv format using this command:

php artisan ab:export /path/to/file.csv

If you run that command without a filepath, it will write it to the console.

Advanced

AB::pageview()

Used to manually trigger an pageview.

AB::interact()

Used to manually trigger an interaction which results in engagement.

AB::complete($goal)

Used to manually trigger goals. Useful when you want to track goals that are not linked to urls or routes.

AB::getExperiments()

Get the list of experiments.

AB::getGoals()

Get the list of goals.

More Repositories

1

agent

👮 A PHP desktop/mobile user agent parser with support for Laravel, based on Mobiledetect
PHP
4,541
star
2

imagehash

🌄 Perceptual image hashing for PHP
PHP
1,976
star
3

date

🗓 A library to help you work with dates in multiple languages, based on Carbon.
PHP
1,813
star
4

optimus

🤖 Id obfuscation based on Knuth's multiplicative hashing method for PHP.
PHP
1,264
star
5

php-proxy

A PHP proxy script with https and post support
PHP
933
star
6

blade

🔪 A standalone version of Laravel's Blade templating engine for use outside of Laravel.
PHP
823
star
7

model

This model provides an eloquent-like base class that can be used to build custom models in Laravel and other frameworks
PHP
379
star
8

RTL8188-hostapd

hostapd for Realtek RTL8188
C
333
star
9

laravel-rollbar

Rollbar error monitoring integration for Laravel projects
PHP
329
star
10

captain

⚓️ Easily start and stop docker compose projects
Go
241
star
11

codeigniter-hmvc-modules

Create HMVC modules with this lightweight extension for Codeiginter 2
PHP
188
star
12

codeigniter-advanced-images

Resize and crop images on the fly
PHP
181
star
13

dashboard

A server dashboard for Ubuntu
PHP
136
star
14

codeigniter-template-library

A template library for Codeigniter
PHP
107
star
15

laravel-raven

Sentry (Raven) error monitoring integration for Laravel projects
PHP
90
star
16

laravel-mongodb-session

A MongoDB session driver for Laravel
PHP
77
star
17

codeigniter-authentication-library

A secure authentication library for CodeIgniter
PHP
68
star
18

laravel-oauth

A Laravel OAuth 1 & 2 library
PHP
65
star
19

laravel-mongodb-sentry

An extension for Laravel-MongoDB that lets you work with Sentry
PHP
54
star
20

codeigniter-message-library

Store and display error or information messages to display on the current page or next page
PHP
51
star
21

lean

Use the PHP League's Container package with auto-wiring support as the core container in Slim 3
PHP
31
star
22

laravel-mongodb-core

A MongoDB based query builder for Laravel
PHP
28
star
23

php-chef

Opscode Chef API PHP library
PHP
20
star
24

chef-patch

Helps you replace text and lines in files from Chef recipes.
Ruby
20
star
25

palenight.zsh-theme

My custom zsh theme
13
star
26

laravel-mongodb-lite

A lightweight MongoDB database library and model for Laravel 4
PHP
11
star
27

vagrant

My personal Vagrant development environment
HTML
7
star
28

quotebot

Quotebot for slack
TypeScript
5
star
29

docker

My personal Docker setup
5
star
30

docker-php-cs-fixer

A tool to automatically fix PHP coding standards issues
4
star
31

ddd-oke-cars

PHP
4
star
32

docker-php

Custom PHP docker image with some basic extensions
Dockerfile
4
star
33

cryptonope

Replace crypto words with random things
JavaScript
3
star
34

homebrew-custom

Custom homebrew formulas
Ruby
2
star
35

auto-commit

JavaScript
2
star
36

spacegray-monokai

A Monokai color scheme for Sublime's Spacegray theme
1
star