Title: A/B split testing with Google Analytics
Last modified: August 21, 2016

---

# A/B split testing with Google Analytics

 *  [leon1907](https://wordpress.org/support/users/leon1907/)
 * (@leon1907)
 * [12 years ago](https://wordpress.org/support/topic/ab-split-testing-with-google-analytics/)
 * Hi,
 * I am trying to do an A/B split test with my homepage. I made a second homepage
   and set up my experiment in Google Analytics.
 * Now i am trying to add the code from google in my Header.php after the <Head>
   tag. When I do this no other page of my WordPress site works anymore and every
   page links back to the new home page I want to try out.
 * I googled it and found this solution which i placed on the bottom of this message.
   However, when I try this my whole site goes down!
 * Can somebody help me with this problem?
 * Thanks in advance.
 * Léon
 * ‘Firstly, log in to your WordPress site as an administrator and browse to the
   edit screen for the original page. Once there, look in your browser’s URL bar
   to get the page ID from the URL.
 * Getting the WordPress page ID
    Now fire up your favourite code editor and open
   the header.php file in your active theme directory. Below the first <head> line
   add the following code, substituting your page ID instead of ***PAGEID***, and
   the experiment javascript code provided by Google Analytics in place of ***GOOGLECODE***;
 * 1
    2 3 4 5 <?php if (is_page(***PAGE ID***) ):?>
 * ***GOOGLECODE***
 * <?php endif; ?>
    Simple as that! Using the is_page function allows us to surround
   the output of our experiment code in a conditional statement – if the current
   page ID matches the ID of your original experiment page, the javascript will 
   fire and the Google experiment will work.

Viewing 1 replies (of 1 total)

 *  [Hudson Atwell](https://wordpress.org/support/users/adbox/)
 * (@adbox)
 * [12 years ago](https://wordpress.org/support/topic/ab-split-testing-with-google-analytics/#post-4914140)
 * Hi if you are looking to rotate js scripts on the homepage in a certain location
   then instead of coding the logic into PHP there is a handler that can help you
   do this in the Calls to Action plugin here on the repository.
 * I may not have understood the post correctly though:
 * [http://wordpress.org/plugins/cta/](http://wordpress.org/plugins/cta/)

Viewing 1 replies (of 1 total)

The topic ‘A/B split testing with Google Analytics’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Hudson Atwell](https://wordpress.org/support/users/adbox/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/ab-split-testing-with-google-analytics/#post-4914140)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
