Laravel A/B - Testing
Here is an example use case of a nested A/B test tracking signup and free trial goals
Lets assume the following blade template
welcome.blade.php
<html>
<head>
<title>My Website</title>
</head>
<body>
@ab('hero-text')
@condition('my website')
<h1>My Website</h1>
@condition('welcome user')
<h1>Welcome, {{ $user->name }}</h1>
@ab('free offer for new users')
@condtion('free trial')
<button>Start your free trial</button>
@condition('get started')
<button>Get Started</button>
@track('free trial')
@track('sign up')
</body>
</html>
You can also easily test logic within you Controllers
class PagesController extends Controller
{
public function welcome()
{
$option =
Ab::choice('kind of homepage', ['control', 'variant'])->track('go-to-ab');
if ($option === 'variant') {
return view('variant-welcome');
}
return view('welcome');
}
You can either track goals in views or within your application logic.
register.blade.php
<html>
<head>
<title>My Website</title>
</head>
<body>
.... body
@goal('sign up')
</body>
</html
You can also track goals within laravel
RegistrationController.php
public function store(Request $request)
{
.... store logic
PivotalAb::goal('sign up');
if($request->has('free_trial')) {
PivotalAb::goal('free trial');
}
}