How I put the Google Analytics in my ZenCart without A plugin


The Short Answer

Get your Google Analytics Code, open this file on your Zen Cart site:
\includes\templates\MY_Custom_Template\common\tpl_main_page.php

Scroll to the bottom of the file and just before the final line that is:
</body>

Paste in your code from google. Save the file, upload to your live site and that's it.


The Longer Answer

I wanted to add the Google Analytics code (GA code) direct to my site and not to use a plugin for my own reasons. But when I got the tracking code from Google, their instructions were to:

Quote Originally Posted by Google
2. Paste this code on your site
Copy the following code, then paste it onto every page you want to track immediately before the closing </head> tag.
So, I did the sensible thing and created a new google-analytics.js file, and uploaded it to:
\includes\templates\MY_Custom_Template\jscript\

Then I couldn't figure out why it wasn't working.

I searched about on here, and found that some other had the same issue, and suggested adding it before the </body> tag instead. I was a bit concerned, because the post I read were from a while ago, and things change online so quickly.

But, I had a go at the method I mentioned above (see my short answer), and the new Real-Time beta reporting on GA showed results immediately :) So, all I know that this method works today 18 June 2012 on Zen Cart v 1.5.0

I wrote this to hopefully save others having to search through tons of posts in mixed threads to find the answer to this problem.

Should you want a Plugin instead, you could try this one: http://www.zen-cart.com/downloads.php?do=file&id=272
(I am not connected with this)

If you want a bit more help with the whole process of setting up a GA account, getting the code and integrating it, one of the contributors on here wrote an article on this: http://pro-webs.net/tutorials/settin...racking-basic/


I don't know if the way that I have outlined here is the 'proper' or 'recommended' way of doing this, but it appears to work.

I hope this helps to save some some time for some people.

Paul