Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Do A/B Split Testing in WordPress using Google Analytics

Last updated on by
Elegant Themes
How to Do A/B Split Testing in WordPress using Google Analytics

Sometimes little changes in a page’s design, copy, or layout can significantly improve its performance and conversion. But how do you find what changes works best for you? This is where A/B Split Testing comes in. It allows you to test different versions of a page to find out which version gives the best results. It is a commonly used technique by many professionals to improve their website’s conversion. In this article, we will show you how to do A/B split testing in WordPress using Google Analytics.

How Split Test Works

Preparing for A/B Split Testing

Before we move forward, there are a few things you would need for this tutorial. If you haven’t already done so, then the first thing you need to do is install Google Analytics in WordPress. The second thing you would need is variations of the original page that you want to test. For example, if you are running tests on your registration page, then create another copy of the page with different copy, style, or layout. You can create multiple variations of a page with different layouts or copy. Make sure that you publish your original page and all its variations, so that they are publicly accessible.

Setting up Content Experiment in Google Analytics

A/B split testing is called Content Experiments in Google Analytics. Sign in to your Analytics account and then go to Content » Experiments. Provide the URL of your original page and click on create experiment button to get started.

Start A/B Testing Content Experiment in Analytics

On the next page you will be asked to provide a title for this A/B testing experiment and choose an objective for it. Objectives are goals which you can create in Google Analytics. You can create a new goal by clicking on add an objective link, or use an existing one. Analytics will track how many visitors to each variation of page meet your objective or goal. For example, if you have a registration page where users are redirected to a thank you page after registration, then you can set that as your objective. When a user on your website fills the form and gets redirected to the thank you page, then this equals to the completion of your goal.

Setting up A/B testing or content experiments in Google Analytics

After providing your original page URL and choosing objective or goal for this experiment, you can now add variations of this page. Create different variations of this page in WordPress and make sure all of them are live and publicly accessible. You can add multiple variations of the same page with different design, call to action, layout and copy.

Adding page variations in Google Analytics Content Experiments for A/B Testing

On the next screen you will be provided with a code to add to your WordPress website’s header. Click on Manually insert the code button and copy the code.

Copy the code for A/B Testing content experiment code from Google Analytics

Now all you need to do is add this code to your WordPress theme’s header.php file. Once added, this code will start redirecting all visitors to a variation of your testing page. To add the split test code, you need to paste this code in your theme’s header.php file:

<?php if (is_page($page_id)) :
//Add Google Analytics Content Experiment
 ?>

Paste content experiment code here 

<?php endif; ?>

Replace $page_id with the id of your original page. (See how to find a page ID in WordPress).

If you don’t want to modify the code in your theme, then you can use this plugin called Google Content Experiments.

Once you have added the code to your original page and published the original and variation pages, go back to Google analytics and click the Next button. Analytics will now verify that you have the content experiment code properly installed on your pages. After that you can click on start experiment button to launch your A/B split testing content experiment.

A/B Split Testing Content Experiment Launched in Google Analytics

That’s all you need to get started. You have successfully installed A/B Split Testing on your WordPress site using Google Analytic’s content experiments. It will take some time before Google Analytics will start showing test data. Visitors to your original page will now be randomly redirected to one of the variation pages and some would still see the original page. Users will continue to see the same variation of the page on their next visits during the experimentation. Based on your goal settings, Google Analytics will show you which variation is working best towards achieving your goal and will choose a winner if it feels that one variation is out-performing other variations of the page.

We hope that this article helped you learn how to do A/B split testing in WordPress using Google Analytics. If you have any feedback or questions for us then you can find us on Twitter and Facebook or leave a comment below.


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »

Comments

  1. Mathan says:

    If i use the two variation of the page. How can i avoid duplicate issue becuase i am duplicating the same content of page and with small variation. What suggestion can you give for this?

    Can i give no index, no follow to that page or confused.

  2. Ruben says:

    I want to say thank you for posting this tutorial. I was able to set up our first ever A/B split test thanks to this tutorial.

  3. Jeanette says:

    This is a great article! So by adding in the Google code into the WordPress site, it handles all the redirecting? I don’t need to pay for any other tools to do A/B Testing?

  4. Pat says:

    how do you turn this off once your start

    • WPBeginner Support says:

      Go to Google Analytics -> Content Experiments tab. Find the content experiment you want to stop and click Edit link. You will see a button to stop a content experiment.

  5. Bob says:

    Can I split test more than one page at a time? For example, I may want to test two versions of my landing page and two versions of my subscription page. Your instructions indicate that I must put the page ID in the inserted code. How will this work for multiple page tests?

    • WPBeginner Support says:

      Lets assume that the page id for your landing page is 34, and two versions of your subscription pages have ids 40,42 here is how you would include them in the test:

      <?php if (is_page(34,40,42)) :  ?>
      
      <!-- Analytics Content experiment code-->
      Paste content experiment code here 
      
      <?php endif; ?>
      
      
  6. Christian Ullmark says:

    Hi,

    Can we A/B test from a certain trafik source instead of testing the ladning page?

    For example:. We have bought a banner from wired.com. We want to test if a landing page achieves a better conversion rate than sending the trafik to our start/home page. Thus we would need send the trafik from the banner to two different pages. Does this work in Experiments?

    If so how is this acheived?

    Thank you very much for your help!

    Christian

    • WPBeginner Support says:

      Yes sure. You will have to add Google Experinments code to home page. For example, you can add this to your fucntions.php file

      <?php if (is_home()) :
       ?>
      
      Paste content experiment code here 
      
      <?php endif; ?>
      

      OR

      <?php if (is_front_page()) :
      //Add Google Analytics Content Experiment
       ?>
      
      Paste content experiment code here 
      
      <?php endif; ?>
      
      • Christian Ullmark says:

        Hi,

        thank you for getting back to me. what i do not understand is how the code you are talking about splits trafik from certain sources?

        C.

        • WPBeginner Support says:

          You add those pages while setting up your Google Analytics experiment. One page is set as the original and other pages can be added as variations.

  7. Christian Ullmark says:

    When entering the landing page we want to A/B test “Enter the URL for the page you want to improve” if we use the url for the actual page what happens to traffic that is sent there from media buys where we have put on a google string? Will this traffic also be A/B tested?

    Thank you very much for your help!

  8. Lloyd says:

    Very useful, thank you for taking the time to post. I’ve been using other methods to split test, and have never thought to try it this way.

  9. Bongo says:

    Interesting stuff guys, this looks impressive. I’m keen to know the answer to BART’s question…

    • Editorial Staff says:

      It doesn’t make any sense to split-test your entire site. Not sure what specifically you’re trying to do.

  10. Bart says:

    hi There,

    interesting method. I used the header method but I want to add the code to every page of my website.

    any ideas?

    • Editorial Staff says:

      You want to split test your entire website?

      • Bart says:

        No I want to add the code to every page off my website.

        • Editorial Staff says:

          Remove the if conditional tag. But again, it’s probably not a good idea to do that. Split-testing should be done for page by page basis. Or if you’re trying to split-test a specific element in design (i.e sidebar optin form), then use another script.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.