Setting Up Simple A/B Testing With Google Analytics Experiments and WordPress
If you’re anything like me, you obsess over driving more traffic to our websites, which makes complete sense. I mean, what’s the point of spending time and money on your site if nobody sees it?
But what about once people have actually reached your site? Are you giving enough thought to what visitors actually do on-site other than having a contact button or other call-to-action (CTA).
What you should be doing is CRO. And testing with Google Experiments, which is what we’ll be walking through in this article.
CRO, or conversion rate optimization, is exactly that, optimizing for increased conversions. What is a conversion? A conversion can be any action that you desire a visitor take on-site. For example, a conversion could be a visitor registering for an account, purchasing a product or signing up for an email newsletter. It could also simply be sharing an article on Facebook or watching an embedded YouTube video.
Carrying out CRO generally involves a number of stages:
- Discovery: Gathering relevant data and creating hypotheses
- Testing: Design and implementation of tests, such as A/B or multivariate testing
- Review: Analysis of the data gathered during testing
CRO is often a cyclical process. Once the review stage has been completed the process begins again, now taking advantage of the data gathered during the previous round of testing and analysis.
Choosing What to Test
Once you have decided you want to optimize your website’s conversion rate, the challenge is then deciding what it is you actually want to test. This is obviously specific to each site, but it will be determined by the purpose of the WordPress website and any data gathered during the research stage of the CRO process.
For example, imagine you have an eCommerce site selling shoes and you’re running a promotion where visitors get a free hat. You expected this to boost conversions but instead your analytics show no increase in sales at all.
Upon reviewing your product pages, you can see that the banner for the free hat promotion is actually below the fold. Based off of this, you decide you want to test moving the free promotion banner above the fold, which requires a slight redesign of your product pages.
As you can see, what you want to test can be very specific to your website, your target market, and your product/service.
When choosing what to test, it’s often a good idea to test one element of the page. When only changing a single element, it is easier to conclude that it is that one variation that is having an impact. For example, if you decide to change the layout of the page, the main image, the copy, the button colour and button text, then how can you know which element variations specifically had a positive effect on conversions?
It’s also worth noting, that you should ideally test pages that have a reasonable amount of traffic. This is so that you can get results that are statistically significant within a reasonable time frame.
Tools You Can Use for Testing
There are a number of paid solutions on the market. These range from platforms like Unbounce, which seem to be aimed at smaller businesses, to enterprise level solutions such as Optimizely.
These tools offer some great features, particularly in terms of landing page creation. However, what if you don’t have the budget for these tools? Perhaps your setup is simple and your don’t want to use complicated tools. Well, we can easily use Google Analytics Experiments to A/B test your WordPress website.
Google Analytics Experiments
How to Setup Google Analytics Experiments
Once you’ve decided what you want to test, it’s time to set up the experiment. In this example, we’re going to test changing the main heading of a webpage. We’ll assume it is a site selling shoes and our page is about a new shoe being released.
Defining the Experiment
So, we know we want to test the heading, but what variations do we want to use. If our original heading is “Buy Our New Super Shoe,” we need to come up with a few variants to test. Let’s use these for our example:
- Our New Super Shoe Now Available To Order
- The New Super Shoe – Only £49.99
- The Super Comfy Super Shoe
How are we measuring the success of our experiment? Let’s test how many people click on an “add to cart” button.
Setting Up the Experiment in Google Analytics
Now we have decided what we want to test, let’s configure our experiment in Google Analytics. For this, obviously you will need a Google Analytics account setup for the website you want to run the experiment on. If you don’t have this already, you can read how to setup Google Analytics here.
Choose an Experiment Objective
- Go into the account and view for the website you want to run the experiment on
- Click on the Reporting tab
- Expand the Behaviour menu item on the left and then click on Experiments
- On the All Experiments screen, click the button labelled Create experiment
- Type in a name for this experiment, e.g. “Heading Test”
- Choose the objective for this experiment. For this, we will assume there is a click event set up on the “add to cart” button. If you are unsure of how to do this, you can read about setting up event tracking here and how to set up goals here.
- Select what percentage of visitors you would like to be included in this experiment. For this, we will choose 100%.
- Click on Next Step
Configure Your Experiment
- Add the URL you will be testing as the original page and give it a name, e.g. Original Page
- Click on Next Step
Setting Up Your Experiment Code
- Select the option Manually insert the code
- Click Next Step
- Click on Start Experiment
Implementing Variations in Theme Templates
Note: If you are using a theme created by someone else, then you should create a child theme. This will avoid the changes you are making being over-written if the theme is updated.
Let’s make sure we don’t include the Content Experiments’ code snippets on every page of the site, and only on the page we are actually testing. We’ll add an action with a conditional that loads the following snippets using
wp_head() only if we are on a specific page.
Open up your functions.php file and add the following code:
What we have done is create a function that will add something to the head element. We have also included a conditional using the
is_page() function taking the page ID of the page we want to test as an argument. Change this page ID to the ID of the page you want to test.
chooseVariation() method within the conditional we just created. Update the function we just added to be as follows:
Once this code is installed, then we want to add the code that will create the variants we are testing. For our example, we are testing four headings including our original. We will create an array named
pageVariations where the index of each value in the array corresponds with the index of the variant we set up in our Google Analytics experiment, i.e. the original has an index of
0, variant one has an index of
content_experiments_head_script() function in our functions.php:
Save your functions.php file and everything should be ready to go.
Publishing the Changes and Running the Experiment
chooseVariation() method and also including the code to change your heading to the correct variant.
You may also see one of the variants of the page you are testing. If not and you would like to test it, either clear your cookies or simply keep opening new windows in Google Chrome’s incognito mode until you see a page variant rather than the original.
Analyzing Your Results
One of the great features of Content Experiments is that you can set the level of statistical significance. Google Analytics will keep running your experiment until either the duration of the experiment comes to an end or a statistically significant result is achieved. Google Analytics will inform you of which variant was the winner, if there was one. It is then for you to decide whether you want to implement that variant as the main version of your site.
Your next steps are to decide if you want to run another experiment to further optimize your site. If so, create some new hypotheses and get to testing!
Setting up and running Google Analytics Content Experiments is not that difficult. In fact, the most challenging part is probably deciding what to test!
Experiments are a great way to increase your conversions and get deeper insights into your visitors’ behaviour and what makes them tick.