Share this page: Follow me to be notified of new articles:

A/B testing

What is it?

Basically, an A/B test is a marketing test : you display 2 buttons, one red, one pink to 2 different groups of users. You follow the click and conversion rate of these 2 buttons and keep the best one.
This script will allow you to display between 2 and 5 different versions of the same element.
You can monitor the number of displays of each element, the click rate and the conversion rate.
Because it's basic/simple and relies on one MySQL table with only a few entries, it's pretty efficient. We used it on our AdServer ClicManager (in French) with no issues (our AdServer display around one billion ads a month).
The version published below is a simplified version of the one we use at work. You might need to adapt these scripts to your needs.

You can lean more about A/B testing here.

What do I need?

  1. PHP 4/5
  2. MySQL
  3. A few development skills !

What can I do with the source code?

What ever you want. (learn more)
Would you like to improve it? If you want, send me the updated version and if you want, I'll publish it here. (contact me)

How do I use it?

On the page with 2 versions (or more) of an element :


On the clicked page (ex. subscription form) :


On the confirmation page (ex. subscription's confirmation page) :

Changelog

Source code

You'll need to create this SQL table :


PHP functions :

Check the results

Just run the following SQL query in your database to display the results :


Here is an example of 2 A/B tests we ran on our AdServer :

mysql> SELECT ab.nom as Test_Name, ab.cas as Test_Case, ab.affichages as Displays, ab.actions as Clicks, ab.conversions,
    ->  ROUND(ab.actions / ab.affichages * 100, 2) as CTR,
    ->  ROUND(ab.conversions / ab.affichages * 100, 2) as Conversion_Rate,
    ->  ROUND(100 - (ab.conversions / ab.actions * 100), 2) as Loss_Rate
    -> FROM ab_tests ab
    -> WHERE last > NOW() - INTERVAL 1 MONTH
    -> ORDER BY Test_Name, Conversion_Rate DESC, Test_Case;
+-------------------------+-----------+----------+--------+-------------+------+-----------------+-----------+
| Test_Name               | Test_Case | Displays | Clicks | conversions | CTR  | Conversion_Rate | Loss_Rate |
+-------------------------+-----------+----------+--------+-------------+------+-----------------+-----------+
| Bannieres par defaut CM | a         | 51732829 |  47368 |          15 | 0.09 |            0.00 |     99.97 |
| Bannieres par defaut CM | b         |  1939719 |    698 |           0 | 0.04 |            0.00 |    100.00 |
| Bannieres par defaut CM | c         |  2179485 |   1822 |           1 | 0.08 |            0.00 |     99.95 |
| Ecusson CM              | a         | 22496778 |   1900 |           4 | 0.01 |            0.00 |     99.79 |
| Ecusson RA              | a         |  1918905 |      3 |           0 | 0.00 |            0.00 |    100.00 |
+-------------------------+-----------+----------+--------+-------------+------+-----------------+-----------+
5 rows in set (0.00 sec)
Last update of this page: March 27, 2017
Please do not copy any of the content of this website without asking me first.