Category Archives: content experiments

How To Set Up Google Content Experiments in Magento 1.7

I spent a lot of time looking around for a way to conduct Google Analytics Content Experiments in Magento with very little success. I did find this post in Finnish that detailed one approach and I adapted his findings (with the help of Google Translate) in to the following solution.

Step 1 – Set up your Content Experiment code block
In CMS > Static Blocks add a new static block with an easy to identify name such as “Google Content Experiments Code” and an identifier such as “google_code_block”. Paste the Content Experiments code in to the wysiwyg editor by pressing the HTML button and pasting the code in to the pop up window. Click “update” and the window will close but you won’t see anything appear in the wysiwyg window. This is normal.Make sure you enable the code block and save it.

Step 2 – Alter your template to write the code block
In your appdesignfrontenddefaultyourtemplatetemplatepagehtmlhead.phtml file add the following code right at the top after meta charset="UTF-8"

<?php  $routeName = Mage::app()->getRequest()->getRouteName();
$identifier = Mage::getSingleton('cms/page')->getIdentifier();
if($routeName == 'cms' && $identifier == 'home') {
echo $this->getLayout()->createBlock('cms/block')->setBlockId('google_code_block')->toHtml();
} else {


If you are performing an experiment on a page other the home page you will need to change the $identifier string to match your page identifier which is your URL key. You will also need to change the Block ID if you have called your code block something different.

Step 3 – Disable the code block on your variation pages
Set up the variations of your CMS page and in the Layout Update XML part of the Design tab paste the following XML code:
<reference name="head">
<remove name="google_code" />

This will stop the code block from loading on the variation pages as per Google’s instructions.

Step 4 – Verify it all works in Google Analytics!
Check it all works in GA and start your experiment.

I’ve yet to work out a way to perform experiments on category pages without creating a brand new category containing the same products.