Track non HTML files with Google Analytics
Thursday, May 29th, 2008Google Analytics is based on Javascript. Since Javascript can be placed only in HTML files, tracking non HTML files like pdf, zip, mp3 and others is a little bit tricky. But it is possible.
In order for Google Analytics track downloads of an mp3 file from your site, do the following:
1. Add the Google Analitycs tracking code ABOVE the the link to your downloaded file. If you already have the Google Analytics code in your site footer, and you probably do, place the same code again, but remove the call to _trackPageview().
example:
<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-xxxyyyy-z”);
pageTracker._initData();
</script>
2. Edit every link you want to track, in the following way:
In case your link looks like this:
<a href=”/downloads/file1.mp3″>Hava Nagila</a>
change it to look like that:
<a href=”/downloads/file1.mp3″ onClick=”javascript: pageTracker._trackPageview(’/downloads/HavaNagila’); >Hava Nagila</a>
The clicks on this link will appear in Google Analytics as if the page /downloads/HavaNagila was actually viewed, even though there isn’t really such a page.
You can read more about this issue and others in Google Help Center.
|











