Our agency doesn’t believe in using the word “like” when discussing design, content, or just about anything really—except maybe food and drinks. Rather than saying like, we replace it with statements such as “this color makes me feel” or “based off our users, I feel this would be more effective.” Though we strive to live by this, there are still times when we need more information to determine which is the best direction. This is where A/B testing comes in.

Although there are a few different platforms to use for A/B testing, we primarily work with two, Optimizely or Google Experiments. In this post, I will walk you through how to set up an A/B test using Google Experiments for your WordPress site.

A/B Testing Best Practices

When setting up your A/B testing, you want to be certain you are testing a hypothesis, and a good hypothesis is a strong statement. For example, “When the call-to-action is red instead of blue, more users will convert.” Other best practices include the following:

  • Set up accurate conversion points.
  • Stop the testing on the same day of the week as it began.
  • Be wary of holidays or seasonal occasions when testing.
  • Don’t stop it too soon—this will largely depend on the number of users on your site.

Most importantly, be sure that you check your test on all the browsers your users will be using.

How to Set Up Google Experiments on a WordPress Site

Step 1: Get the Experiment Script

Once you have signed into your Google Analytics account, go to Behavior > Experiments, and click the “Create Experiment” button.


On this screen, you will be asked to name the experiment and to select a metric to measure. The metrics or goals to test will depend on your experiment. If your team has not set up goals, I highly recommend doing so by either page URLs or event tracking if needed. Next, set the percentage of traffic to experiment, and select “Next Step.” On the next page, you’ll be asked to enter the URLs to test.


Enter the original pages URL and name it; then enter the variation pages URL and name it. Check to make sure that the pages are correct by reviewing the page previews. Once complete, click “Next Step.”

On the next screen, click on “Manually insert the code,” and copy the script provided. If you need to, click “save for later” so you will have time to send up the code on your site without losing the experiment settings created.


Step 2: Add the script to your WordPress Site

Before you can set up your experiment, you need to add a simple code in the header.php file. This code will check for a predetermined page ID.  If it is a match, run the experiment; it will also include the script from Google Analytics to run the experiment. The code is:

<?php if (is_page($page_id)) :
//Add Google Analytics Content Experiment
Paste content experiment code here
<?phpendif; ?>

Replace the $page_id with the ID of your page. You can find the ID by hovering over the page title when logged into WordPress and viewing the list of all the pages on your site.  For example, the page in this image’s ID is 14:


Once you have the code added to the header.php file, you can return to Google Analytics and review the experiment. If everything looks good, click on the “Start Experiment” button.

It takes up to 12 hours to start seeing data in Google Analytics. Users will be given either the original version or the variation, and each time they return, they will be given the same version until the experiment ends or they clear their browser history. Based on your goal settings, Google Analytics will show you which variation performs better, allowing your team to choose the best option.


After you have successfully set up your first experiment, you’ll start seeing how valuable A/B testing is and appreciate everything it provides your team.

Hire Gravitate. Get Results.