Using Google Analytics as an Alternative to Website Optimizer

by Will Reinhardt December 22nd, 2009 

Recently while doing some banner conversion rate testing with an eCommerce client, we found that our numbers were not adding up correctly. The problem was that Website Optimizer limits the test set to a specific action on the part of the consumer, essentially placing blinders on our testing efforts. With eCommerce sites though, there are many more variables to consider — we want to know how many people clicked on the test as well as how many made a purchase.

Our solution was to add some new code that performs the logic to determine who see what, and let the custom segmentation within Google Analytics handle the responsibility of reporting the results. With this approach we're able to get a much more complete picture of any given test which allows us to more accurately determine ROI.

Sample Split Test

Let's go over a sample scenario before getting to the code. You run a site that sells headphones, and you're interested in testing a two versions of the homepage for a new type of high-end headphone. You're giving up prime real-estate by running this split test on your homepage, so it's important to earn as much as you can.

Our simplified consumer experience might look a bit like this:
customer-funnel

If we're only using Website Optimizer the issue then becomes, from which point to which point do we consider to be a conversion? In Website Optimizer we can only select a single point A and a single point B, we can't track the customer's path through the entire funnel. That's the unacceptable dilemma we're working to overcome. If we have single point-to-point tracking then we can only pick one of the following items to measure:

  1. Are visitors clicking on the banners?
  2. Are visitors adding the product to the shopping cart?
  3. Are visitors making the purchase?

None of these individual conversion rates can tell the entire story — we need more information.

Getting Our Hands Dirty

Website Optimizer is a great tool to track any one of these paths, but it cannot track all of them the way Google Analytics can. Our goal then, is to create an easy to use system that will allow us to track all of these paths and help us identify where we're losing customers.

I'm including the PHP code we used for those of you that may find it useful. If coding is not something you enjoy then the PHP code below may look daunting. Conceptually though, this is all it's doing:

customer-choice

We want to make sure that if a user comes back while the split test is still going on, that they have the same experience.

class SplitTest
{

public $strSelected = "";
public function __construct($strCookie, $arrShuffle, $strOverride, $datCookieAge=null)
{

$datCookieAge = empty($datCookieAge) ? time()+60*60*24*7 : $datCookieAge;

// Code for segmenting to track in Analytics
$strSelected = sanitizeInput($strOverride);
$strSelected = isset($_COOKIE[$strCookie]) && empty($strSelected) ? $_COOKIE[$strCookie] : $strSelected;

// If still empty, randomize it.
if (empty($strSelected))
{

shuffle($arrShuffle);
$strSelected = $arrShuffle[0];

}
if (!in_array($strSelected, $arrShuffle))
{

$strSelected = $arrShuffle[0];

}
$this->strSelected = $strSelected;
setcookie($strCookie, $strSelected, $datCookieAge);

}

}

You would call this code with the following:

<?
$arrShuffle = array("layout1", "layout2");
$SplitTest = new SplitTest("layoutTestName", $arrShuffle, "variableName");
$strWhichVersionToShow = $SplitTest->strSelected;
?>
<script language="javascript">
pageTracker._setVar('<?= $strWhichVersionToShow ?>');
</script>
<?
if ($strWhichVersionToShow == "layout1")
{
// Show the first layout here
}
elseif ($strWhichVersionToShow == "layout2")
{
// Show the second layout here
}
?>

The Javascript is what will set the custom segment in Analytics. Once your customers start to visit the homepage they'll start to see one of the two layouts you've created for them, and Analytics will automatically assign them into one segment or another. You can easiely see the full results — including the eCommerce results — by going to Visitors > User Defined. Alternately, you can now create a custom segment with either of your newly defined segments.

Additionally, while you're testing the layouts, you don't want your team to fall into the same segments while they're creating your beautiful new homepage. To avoid this, you can use the override call that's built into the class:
yourdomain.com/homepage.php?variableName=layout1

That way you and your team can always switch back and forth between the various layouts.

Wrapping Up

One thing to know about custom segmentation, Google Analytics only allows users to be grouped into a single segment. If your site is already using segments for another internal process, chances are that this approach will not work for your team. This also means that you can only run a single test at a time, but that's not really a negative. You're only running one split test at a time, right?

This approach may be over-simplified for your needs, but it can go a long way towards getting your team all the information it needs to make great decisions.

Will Reinhardt

Will Reinhardt helps professionals track their keyword rankings over time

seokeywordranking.com

You May Also Like

6 Responses to “Using Google Analytics as an Alternative to Website Optimizer”

  1. Julien Coquet says:

    Actually, you should be using custom variables, _setVar will likely end up being deprecated

    Also, you can use custom vars to track GWO variations

  2. RB says:

    Not bad, but you should keep in mind that there'll be yet another persistent cookie to be sent over the line with each request (something you don't have to worry about when using GWO).

    However, when combined with the new reporting functionality of GA (custom segments can now also be accessed in full through the API), this could work out quite nicely :-)

  3. Lukas says:

    Neat thing. Easy to set up, expand and modify. Had problems with the sanitizeInput function not being initially defined, but other than that it seems to work like a charm.
    .-= Lukas recently posted: Adtaily, czy może być lepiej? =-.

    • Ack, good point Lukas, I apologize. The sanitizeInput method is an internal function that I missed when entering the code.

      I'm glad it worked for you though!