Shopping Cart Forum

Go Back   eShop Forums - eCommerce Help Forum for Shopping Cart Owners. > Shopping Cart Software > Zen Cart & osCommerce
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Zen Cart & osCommerce Tips, advice and help on how to use the most popular free E-commerce shopping carts available.

Reply
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #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,185
Thanks: 1
Thanked 72 Times in 72 Posts
Default How to add Google Analytics to every page on your osCommerce eCart

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-11-2007, 11:37 PM
ICTADVIS ICTADVIS is offline
Junior Member
 
Join Date: Nov 2007
Location: Scotland
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Re: How to add Google Analytics to every page on your osCommerce eCart

Hi Lawrence

I look after an OSCOMMERCE site for a client but it would not appear that the file footer.php situated within INCLUDES is supporting my clients site.

The footer information I do see seems to be editable in a file titled english.php that has a section contained within it saying define footer text and here I can edit text that I want to appear on every page. However, the actual footer file situated within INCLUDES looks nothing like what you refer too.

Appreciate your advice on where I might be going wrong?
__________________
ICTADVIS
www.ictadvisor.com
info@ictadvisor.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-11-2007, 03:32 AM
Lawrence Lawrence is offline
Forum Admin
 
Join Date: Aug 2007
Location: Kenley, Surrey, UK
Posts: 1,185
Thanks: 1
Thanked 72 Times in 72 Posts
Default Re: How to add Google Analytics to every page on your osCommerce eCart

Hi ICTADVIS

It is possible that your client is running an older version of osCommerce than the one I used in my example so the code will be slightly different. The principle is still the same, place the Analytics code after the last ?> in includes/footer.php. To check it's actual position on a page, open the site in your browser then view the source for the page. It should appear just before the </body> tag.
__________________
Lawrence
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-11-2007, 05:05 AM
Lawrence Lawrence is offline
Forum Admin
 
Join Date: Aug 2007
Location: Kenley, Surrey, UK
Posts: 1,185
Thanks: 1
Thanked 72 Times in 72 Posts
Default Re: How to add Google Analytics to every page on your osCommerce eCart

One problem that you're likely to encounter if you use SSL on the server is that you will get a security error when your browser changes from http to https. To get around this, you use https://ssl.google-analytics.com/urchin.js instead of the normal Google address when in SSL mode. To enable OSC to switch between the two, you delete the urchin call from the example above and insert this snippet immediately before the last ?>

PHP Code:
if ($request_type == 'SSL') { 
echo 
'<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"></script>'
} else { 
echo 
'<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>'

I used the OSC variable $request_type in that example, if you want to do the same thing on another system, then use this more generic if statement in place of the one used above.

PHP Code:
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') { 
__________________
Lawrence
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.eshopforums.com/f13/how-add-google-analytics-every-page-your-oscommerce-ecart-106/
Posted By For Type Date
javascript code in .php footer? This thread Refback 05-10-2007 01:35 AM

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a linkable image to your sig Nick Forum Issues and Suggestions 0 08-08-2007 07:13 AM

Google

Edible Graphics, Affordable E-Commerce, Web Shops & Custom Form Scripts
Vista Print
tech news, product reviews, the latest home and business technology, the latest in digital imaging


Content Relevant URLs by vBSEO 3.0.0