I have a website where I have .tar.gz, .zip and .dmg files. I need to track the number of downloads using google analytics. I heard that I can use onclick="pageTracker._trackPageview('/file_name.file_extension') for the "a" tags on the page. I'm not clear what the file_name.file_extension corresponds to. Also, do I need to use some additional scripts?
I'm not clear what the file_name.file_extension corresponds to.
Your example onclick="pageTracker._trackPageview('/file_name.file_extension')
logs every click on that link as a page view for file_name.file_extension
.
You can edit file_name.file_extension
to be whatever you want. It is simply the name of the "page view" that gets passed to Google Analytics and is what will show up in your analytics reports.
Also, do I need to use some additional scripts?
No, adding the above onlick
attribute to each link you want tracked will be enough.
See here for reference. Hope that helps.
Edit:
I assumed you knew you needed the general Google Analytics script for this to work (Thanks to Ryan in the comments for clarifying). The script looks like the following, but contains your Google Analytics account number in place of the X's in UA-XXXXXX-X
:
<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">
try{
var pageTracker = _gat._getTracker("UA-XXXXXX-X");
pageTracker._trackPageview();
} catch(err) {}
</script>
To obtain the script, you'll need a Google Analytics account. Once signed into your account and after adding a new "Website Profile", you'll be given a snippet of Javascript (using your account number) to include in each page you want tracked, along with instructions. That should be enough to get you started, but let me know if I can clarify anything.
Edit 2:
As pointed out in the comments, I erroneously posted the latest, asynchronous version of the Google Analytics script which is actually incompatible with _trackPageview
. I've edited my answer to include the "traditional" script that you'll want to use. See here for more info.