Sep
Fix Google Analytics Tracking Code On 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’) ?>

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!





