Loading...
Page tree
Skip to end of metadata
Go to start of metadata

Overview

Split testing (or A/B testing) is a method to compare multiple variations of web page design or user-website interaction, in order to find out which version achieves the largest profit. You can test phrases, page elements (their appearance, layout, etc.), and even entire website themes against each other.

Set up split tests

  1. Download the file ABTest.php and place it inside any folder on the server.
  2. Create the tests.php file and list all your A/B tests there. Place it inside the folder where the ABTest.php file is located. 

See an example of the tests.php file below:

<?php
 
return
array(
    array(
        'id'        => 'ab_form_color', // The title of an AB testing campaign to be displayed in Roistat
        'variants'  => array(
            array( 'id' => 'dark'),  // The title of a variant to be displayed in Roistat
            array( 'id' => 'blue'),  // The number of variants is not limited
        ),
    ),
    array(
        'id'        => 'ab_main_title', // The number of campaigns is not limited
        'variants'  => array(
            array( 'id' => 'small'),
            array( 'id' => 'big'),
        ),
    ),
);

 

3. Add the library for A/B testing at the beginning of the page file:

<?php
 
require_once __DIR__ . '/ABTest.php'; // Path to ABTest.php

WARNING

In case the code isn't included at the beginning of the page, errors may occur if any other php code is located above yours.

Single-page website

4. E.g. you wish to evaluate all the changes occurred after a heading on the website is replaced by a new one. In this case:

<?php require_once __DIR__ . '/ABTest.php'; ?> <!-- The library is now added -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
 
...
 
<div class="div1">
  <!-- A campaign and variant titles from tests.php -->
  <?php if (ABTest::instance()->getTestValue('ab_title') === 'old'): ?>
    <h2>Old heading!<h2>
  <?php else: ?>
    <h2>New heading!<h2>
  <?php endif; ?>
</div>

Multi-page website

4. If different pages are to run different tests, all the tests are to be marked as inactive by default. To do this, set ‘active’ => false in the tests.php file:

<?php
 
return
array(
    array(
        'id'        => 'ab_title',
        'active' => false, //  <---
        'variants'  => array(
            array( 'id' => 'old'),
            array( 'id' => 'new'),
            array( 'id' => 'newest'),
        ),
    ),
);

 

5. Then, you should manually enable all the necessary tests for each page:

<?php
 
// Include this code at the beginning of a page
define('ROISTAT_AB_AUTO_SUBMIT', false);
require_once __DIR__ . '/ABTest.php'; // Path to ABTest.php
ABTest::instance()->activateTest('ab_title'); // A campaign title from tests.php
ABTest::instance()->activateTest('ab_second_test'); // If there are several tests on a page
ABTest::instance()->submit();
 
...
 
// Example:
 
<div class="div1">
  // A campaign and variant titles from tests.php
  <?php if (ABTest::instance()->getTestValue('ab_title') === 'old'): ?>
    <h2>Old heading!<h2>
  <?php elseif (ABTest::instance()->getTestValue('ab_title') === 'new'): ?>
    <h2>New heading!<h2>
  <?php else: ?>
    <h2>The newest heading!<h2> 
  <?php endif; ?>
</div>

Compare two variations of the website

When your goal is to compare two website variations, e.g. two landing pages, you should follow theses 2 steps:

1) To store the original referrer in a cookie;

2) To redirect from the first page to the second one without losing any link labels.

Two pages under one domain

If you wish to compare two website variations available under one domain, e.g. site.ru/lp1 and site.ru/lp2, follow these steps:

1) Configure the variant to test in the tests.php file:

tests.php
<?php
 
return
array(
    array(
        'id'        => 'ab_two_versions', // ab_two_versions - the title of a test to be displayed in Roistat
        'variants'  => array(
            array( 'id' => 'old'),  // old - the title of a variant to be displayed in Roistat
            array( 'id' => 'new'),
    ),
);

 

2) Insert the following code in the first page (this version is the original one):

?php
 
// Include this code at the beginning of a page
define('ROISTAT_AB_AUTO_SUBMIT', false);
require_once __DIR__ . '/ABTest.php'; // Path to ABTest.php
ABTest::instance()->activateTest('ab_two_versions'); // The title of a test from tests.php
?>
 
// The redirection is to start before the web page content is loaded, therefore the redirection code is to be inserted in the beginning of the code
<?php if (ABTest::instance()->getTestValue('ab_two_versions') === 'new'): ?> // If the value is new, the redirection starts
    $param = !empty($_SERVER['QUERY_STRING']) ? "?" . $_SERVER['QUERY_STRING'] : ""; // All the link labels are stored here
 
    setcookie("roistat_referer", isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "");
    header("Location: http://site.ru/{$param}"); // Change the web address site.ru to a new one where the user is to be redirected to
    exit(); 
<?php endif; ?>
<?php ABTest::instance()->submit(); ?>

Two pages under two domains

If you wish to compare two website variations available under two different domains, e.g. lp1.site.ru and lp2.site.ru, or site1.ru and site2.ru, follow these steps:

1) Configure the variant to test in the tests.php file:

tests.php
<?php
 
return
array(
    array(
        'id'        => 'ab_two_versions', // ab_two_versions - the title of a test to be displayed in Roistat
        'variants'  => array(
            array( 'id' => 'old'),  // old - the title of a variant to be displayed in Roistat
            array( 'id' => 'new'),
    ),
);

 

2) Insert the following code in the first page (this version is the original one):

<?php
 
// Include this code at the beginning of a page
define('ROISTAT_AB_AUTO_SUBMIT', false);
require_once __DIR__ . '/ABTest.php'; // Path to ABTest.php
ABTest::instance()->activateTest('ab_two_versions'); // The title of a test from tests.php
?>
 
// The redirection is to start before the web page content is loaded, therefore the redirection code is to be inserted in the beginning of the code
<?php if (ABTest::instance()->getTestValue('ab_two_versions') === 'new'): ?> // If the value is new, the redirection starts
    $abVariant = "?b=1";
    $param = !empty($_SERVER['QUERY_STRING']) ? "&" . $_SERVER['QUERY_STRING'] : ""; // All the link labels are stored here
 
    setcookie("roistat_referer", isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "");
    header("Location: http://site.ru/{$abVariant}{$param}"); // Change the web address site.ru to a new one where the user is to be redirected to
    exit(); 
<?php endif; ?>
<?php ABTest::instance()->submit(); ?>

 

3) Insert the following code in the very beginning of the redirection page:

<?php if ($_GET['b'] === '1'): ?>
<?php   
    setcookie('ab_two_versions', 'new', time()+14*24*60*60, '/');
    setcookie('roistat_ab', 'ab_two_versions:new', time()+14*24*60*60, '/');
?>
<?php endif; ?>

View the results

To view the results, open the project and go to the Split testing page.

The results screen will help you to understand which version is more profitable.

  • No labels