Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Google Analytics


Guest

Recommended Posts

We are using AdWords to promote our site, and would like to use Google Analytics. In order to do this google supply a snippet of code which they say needs to be placed on every page of your site;

 

--------------

Copy the following code block into every web page that you want to track immediately before the </body> tag.

If your site has dynamic content, you can use a common include or a template

--------------

 

Does anyone know where we should be putting the code, or indeed if it will work with oscommerce?

 

Google also supply two version of the code: New Tracking code & Legacy Tracking Code, which one should be used?

 

Any help greatly appreciated.

Link to comment
Share on other sites

GA works for me and is located before the /body tag on each page I want tracked. Which is exactly what the instructions say ;)

Does it work? Uh huh *nods*

 

Can't help on which code to use, not up to speed on that bit LOL! I only remember one option

Link to comment
Share on other sites

Does anyone know where we should be putting the code, or indeed if it will work with oscommerce?

 

Google also supply two version of the code: New Tracking code & Legacy Tracking Code, which one should be used?

Yes. I've just done this for my site.

Use the new tracking code rather than the urchin legacy code. That way you'll be able to use any new features Google are looking to build in. It works the same.

 

In fact the latest code they supply also covers switching to SSL too (rectifies a problem tripped up on many times on this board already)

 

Here's the snippet I've put in includes/footer.php (at the very bottom):

  <tr>
<td align="center"><?php echo tep_display_banner('static', $banner); ?></td>
 </tr>
</table>
<?php
 if (1) {  // Start of Google Analytics (new style) code
?>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("xx-xxxxxxx-x");   // alter the xxxx stuff to be your GA access info
pageTracker._trackPageview();
</script>
<?php
 } // End of Google Analytics (new style) code
?>

You don't literally have to put it immediately before the closing </body> tag, just advisable to put it somewhere near the bottom of the page. This is merely so that the page loads in the browser before calling the code in case the Google servers have a problem or are overloaded, whatever. That way, your customer doesn't end up with a white screen if Google Analytics throws a wobbly.

 

Notice in my code snippet I've wrapped it in if (1) { ... }. That's so that I can eventually put a flag where the "1" is that will refer to an entry in the configuration table in the database, so I can turn Google Analytics on and off from the admin area. Haven't got around to that yet though so I currently turn it off by setting it to "if (0)" in the source file.

 

Good luck. (Remember Google take a few hours after adding the code before it starts showing anything in the Google Analytics area)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...