View Single Post
  #1 (permalink)  
Old 18-08-2007, 09:12 AM
Lawrence Lawrence is offline
Forum Admin
 
Join Date: Aug 2007
Location: Kenley, Surrey, UK
Posts: 1,226
Thanks: 2
Thanked 82 Times in 82 Posts
Default How to add Google Analytics to every page on your osCommerce store

First thing you need to do is to open an account with Google, you can do that here http://www.google.com/analytics/

Once you have an account you will be given a snippet of code to install on each page you want tracked. On a normal HTML page you will place this just before the </body> tag at the bottom of each page. You may read on some other sites that should place this at the top of the page, you should ignore such advice because if it's placed at the top of a page and there is a delay in the communication with the Google server then your page won't load load until it's finished, resulting in slow page load times and annoyed customers. If placed at the bottom, then the page will load first and be usable before Google has done it's bit.

The code snippet looks something like this

HTML Code:
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2462717-1";
urchinTracker();
</script>
To insert it into each page of OSC (except the admin pages) you need to open /includes/footer.php

At the bottom of which you will see something like this.

PHP Code:
<?php
  
if ($banner tep_banner_exists('dynamic''468x50')) {
?>
<br>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center"><?php echo tep_display_banner('static'$banner); ?></td>
  </tr>
</table>
<?php
  
}
?>
You need to add your Google code to it like this
PHP Code:
<?php
  
if ($banner tep_banner_exists('dynamic''468x50')) {
?>
<br>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center"><?php echo tep_display_banner('static'$banner); ?></td>
  </tr>
</table>
<?php
  
}
?>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2462717-1";
urchinTracker();
</script>
That's all there is to it, you now have Google Analytics on every user page of your osCommerce shopping cart.
__________________
Lawrence
Reply With Quote