WordPress A/B testing with Google Analytics
2012-09-21

<head> I wanted to test a variation of a product page with different copy. I use Google Analytics which has a feature called Content Experiments. Here is how this feature can be used on a Wordpress site.

1. Install Google Content Experiments plugin (at the time of writing it’s at 1.0.0, and I’m using Wordpress 3.4.2).

Unless you happen to be using a theme based on the Genesis Framework, you’ll need to edit the theme file containing <head> (typically header.php) and add the following line just after <head>:

<?php do_action( 'wpe_gce_head' ); ?>

2. Decide what your goal is going to be and set it up in Google Analytics. It could be a visit to a particular page (e.g. a thank you page after a purchase). In my case, the shopping cart and the checkout is on a different domain, so I setup a Google Analytics event which is recorded when the user presses the Buy button.

3. I’ve added the following click handler to the button’s anchor tag:

onclick="if (typeof(analyticsEventTracking) != 'undefined' && analyticsEventTracking=='enabled') _gaq.push(['_trackEvent','Buy button','Page bottom', 'Visual Communication for BAs']);"

I check the analyticsEventTracking variable added by the Google Analyticator plugin. This is to prevent recording the event when a logged in user presses the button (i.e. when I’m testing it myself).

Check that the events show up in Google Analytics. Note that it will take some time (perhaps an hour) before you see them in GA.

4. Set up a variation of your page (or several). This means that you’ll need to create new pages in Wordpress. You probably want to make their URLs similar to the original page, with the addition of a prefix or suffix.

5. Setup an experiment in Google Analytics. You can do this by going to the Standard Reporting section, choosing the Content tab and selecting Experiments. From there, create a new experiment and follow the steps.

You’ll get to choose which pages to include in the experiment.

You’ll also need to put Google Analytics experiment code into your original Wordpress page (but not the variations!). To do this, go to edit the original page in Wordpress. The Google Content Experiments plugin added a section somewhere under the page edit box where you can activate the experiment and paste the experiment JavaScript from Google Analytics.

6. Once the experiment is running, collect enough data for a statistically significant result, and choose the winning variation!