A/B Testing Without Software

A/B Website Optimization Without Split Testing Software

By Friday June 26th, 2015

This is simple and quick method to try out A/B testing before investing in expensive split testing software.

A/B testing is an optimization technique that’s gaining popularity every day.

A/B testing is really hard, though, and it’s expensive. There are a lot of marketers running A/B tests (and taking action on the results), but only a handful of them are doing it correctly. (Don’t believe me? Read about A/A tests here.)

We shouldn’t overlook something just because it’s hard or expensive, though.

We just need to make sure it’s worth it before investing in a platform like Optimize.ly to run A/B tests like a boss.

Consider this simple method to A/B test without software

Consider this simple method to run some quick A/B tests, analyze the results and see if A/B testing is worth your marketing dollars.

We’ll use PHP for this demo (you can use any server-side language) and a custom dimension in Google Analytics. Sound scary? It’s not.

Randomly Choose A or B

The first step to run an A/B test is to randomly choose the A or B version when loading a page.

Here’s PHP code to do that. You can copy and paste this snippet at the very top of any page you want to A/B test.

<?php // A/B Testing

$aB = rand(0,1);
if ($aB == 1) {
    $aB = "B";
} else {
    $aB = "A";
}

?>

That sets up the variable $aB for any page as either “A” or “B” (keep going down the alphabet if you’d like).

The If Statement

The next step is to display different content based on the value of the $aB variable.

Some like to set up separate A and B versions for an entire page, but I like to A/B test one section at a time.

To do this, use a simple if statement to display different content for a section.

<?php

if ($aB == "B") {
    // B content
} else {
    // A content (default content)
}

?>

Showing one of two versions randomly is as simple as that, but it’s only half the battle.

Google Analytics Custom Dimension

We need to analyze other metrics in correlation with the A/B value to know which is performing better.

To do that, we set up a custom dimension in Google Analytics. Again, if it sounds scary, just read on. It’s really not that bad.

Analytics Account Setup

  1. First, sign into Analytics and go to the property for your website.
  2. Next, go to the Admin section, and in the Property column, click Custom Definitions / Custom Dimensions / New Custom Dimension
  3. Now, choose a name (I like “A/B Testing”), set the scope to “Hit” and make sure “Active” is checked.
  4. Save.

Analytics Snippet Setup

Next, make sure your website reports the A/B value to your Analytics account by adding a line to the Analytics snippet on your website.

ga('set', 'dimension1', '<?php echo $aB; ?>');

Note: If the Index on the custom dimension you set up isn’t 1 (meaning you’ve created a custom dimension previously), then use “dimension[index number]” for that second parameter instead of “dimension1.”

That new line goes right above the ga(‘send’,’pageview’); line, so your whole snippet will now look something like:

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXXXXX-X', 'auto');
ga('set', 'dimension1', '<?php echo $aB; ?>');
ga('send', 'pageview');

Make sure you replace those Xs with the number that Analytics gives you for your snippet.

Here’s more info on creating the dimension in Analytics and here’s info about custom dimensions in general.

Voilá

That’s it!

Now that you’re set up to A/B test, remember to A/B test in a smart way.

For instance, only test one change at a time. Also, make sure your sample size is large enough. If it is, make sure you factor in margin of error before acting on your results.

The best way to test smartly is to read everything you can about A/B testing before you begin. There’s a ton of research out there. To start, try Smashing Magazine’s Ultimate Guide to A/B Testing and VWO’s Complete Guide to A/B Testing.

Lastly, if you have any questions, ask us on Twitter (@brolik) or email me at thomasa@brolik.com.

Happy testing!

Oh, you want to know how to get insight from this A/B setup? Watch for a followup to this article where one of our strategists will explain what they do with the data. We’ll add the link when that article is published. 

Like what you just read?

Sign up for updates whenever we post a new article. No spam. Promise.

About the Author

Drew Thomas is the CTO and co-founder of Brolik. He oversees Brolik's technology projects, including Leverage, Brolik’s proprietary technology platform. Drew spends most of his free time on side projects and prefers to blend work and life into a balanced, enjoyable experience. He lives in Austin, TX.
Twitter: @drewbrolik
LinkedIn: Drew Thomas
Google+: Drew Thomas