home forums resources search newsjoinmembers: 5824
Main Network: Joomla Wordpress Drupal Drupal.se Fireorb Flash Java PHP Ruby Windows Linux
 videos
 articles
 blogs
 comments
 downloads
sitemap
Carl | Tue, 2007-12-25 11:00  tags: , ,

W
hile updating the Hiveminds website I thought that we should be tracking downloads via Google Analytics. I had two reasons for doing this. The first was to have a proof that it could actually be done because of constantly being ignored by management. For some reason they always bring up the subject of tracking downloads , flash and internal campaign links but there ears and minds shut down whenever the solution is to use Google Analytics. I found this irritating because they seem to put so much trust in the daily running of the business in the hands of Google Analytics stats. The second reason is because I wanted to trim down the number of calls to the Drupal watchdog module.

Google Analytics Javascript Upgraded

While doing some research I found that Google has upgraded their Analytics code a couple of months ago. the old urchin.js is being replaced by a newer ga.js. What makes the new ga.js different from urchin.js?

  1. The ability to track events. This is a very important change with Flash, Flex and AIR becoming more popular.
  2. Transparency in the code something that makes it easier to use and integrate Google Analytics into other javascript and server-side scripting languages. This new object oriented stylemeans no more functions like urchinTracker();.
  3. Hard to believe but the file sizes can be smaller for faster downloads.

New Possibilities

This was all positive stuff and made it even easier to accomplish my goals. A lot of things have been changed in the code and somethings that can be done more easily now are the tracking ecommerce transactions and interactive Ajax-based sites.

HTML Page Tag using urchin.js:

<script type="text/javascript" src=" http://www.google-analytics.com/urchin.js "></script>
<script type="text/javascript">
_uacct = "UA-xxxxxx-x"
urchinTracker();
</script>

HTML Page tag using ga.js

<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("UA-xxxxxx-x");
pageTracker._initData();
pageTracker._trackPageview();
</script>

The Download Tracking

The code for tracking downloads looks like this now.

<a href="http://www.example.com/files/map.pdf" onClick="javascript:urchinTracker ('/downloads/map'); ">

But after I am finished upgrading to the newer javascript it will look like this.

<a href="http://www.example.com/files/map.pdf" onClick="javascript: pageTracker._trackPageview('/downloads/map'); ">

As you can see it is fairly easy to implement and if you are using Drupal or another CMS that has a function or method for writing links then it only takes minutes to put into place.

A Word to Open Source CMS Developers

CMS module and extension developers should now be using the upgraded code or get on the ball and change their code. Aside from the many new possiblities within just the plain js code. When the new features are coupled to the backend and administration of a CMS it will serve to remove many of the frustrations associated with statistics that CMS end users experience. Much of the load for granular statistics can now be off loaded to the Google Analytics servers. I sincerly hope that at least the top ten CMS's will be upgraded to the new code especially Drupal and Wordpress.

Lastly, if you are creating new pages maually and not using a CMS then be careful of mixing the two code types. They are not compatible. Mixing could cause you to miss a great deal of information.

Happy Publishing!

Carl's picture
With ten years of experience in web development he spends most of his work day developing in PHP,mySQL and Drupal
Carl McDade - Systems Developer
 
Amazon Web Services Ad Alexa Toolbar Ad Put Your Site Here Developer's Corner Ad
Content Management Systems Wordpress Joomla! Adobe Flex Wordpress Windows Silverlight Content Management Systems Adobe Flex Silverlight
 

Newsletter

Get updates on Hiveminds services, articles and downloads by signing up for the newsletter.

Editor's choice

Some of the better articles, stories and tutorials found at Hiveminds.

Find more

Find more of Hiveminds articles, stories, tutorials and user comments by searching.




Picked links

Hand picked websites and articles from around the web that provide quality reading.

page top