Fix Google Analytics Tracking Code On Magento

fixing-google-analytics-magento

I recently came across a problem while creating a custom theme the other month; I was trying to set up Google Analytics tracking but noticed that the tracking script just wouldn’t appear in the code.

For some strange reason it just wouldn’t load and thus the theme couldn’t track traffic, and more importantly, couldn’t track eCommerce data. After lots of searches in Google to no avail I finally found the solution…

What Was The Problem?

After turning on Google Analytics in the Configuration (System -> Configuration -> Google API) and flushing the cache, the Google Analytics tracking script wasn’t appearing in the websites code.

What Was The Solution?

The short answer is that I missed an important include in the template files. Fortunately, something that is very easy to fix.

Navigate to:

app/design/frontend/default/YOUR_THEME/template/page/

Check 1column.phtml, 2columns-left.phtml, 2columns-right.phtml, 3columns.phtml and any other template files you have for the following line under your opening body tag:

<?php echo $this->getChildHtml(‘after_body_start’) ?>

Google Analytics Code Showing In Magento

It’s always a good idea to reference the base template files if you ever come across an issue like this. If you have any bugs you have solved or questions then feel free to leave a comment below!

Written By Ed Baxter
Hi I'm Ed. By day I'm a search engine marketer working from Sheffield in the UK. By night I'm a designer and blogger, I've worked on a variety of ecommerce websites and in my spare time I love to play tennis. I love to socialise with anyone interested in the web so feel free to drop me a line! Check out Ed Baxter on Check out Ed Baxter on Google+

Leave a Reply