I have a website that has some Google Analytics (GA) code and I wanted to track the downloads made to one file on my site, I googled for a while and found that if I added this code:
onClick="javascript: pageTracker._trackPageview('/descarga_programa_Mono');"
I could track the downloads by just looking at the "descarga_programa_Mono" that would appear on the GA dashboard, however I am not getting any results =/ is there something I'm missing?
My GA code is the newest one as far as I know the one that starts with:
var _gaq = _gaq || [];
and it's before the onClick script that I'm trying to use.
Just to complement,
if you want to make an virtual pageview in a specific button, you can do this way:
<a href="Link to Facebook"
onclick="_gaq.push(['_trackPageview', '/click/facebook/button', 'location.href']);">
<img src="myButtonName"></a>
//Using location.href, you will know in wich page the user was when he was redirected.
Any questions, just ask.
By using onclick (all lowercase) the browser already understands you are using JavaScript.
So that javascript: on your code is unnecessary.
That would be necessary on the href attribute of an a tag.
That pageTracker object you have found is related to the SYNCHRONOUS ga version. NOT the one you are using.
Use _gaq.push() instead as Bruno Brandão pointed out (although, on his example, there shouldnt be slashes around location.href).
The position (head or before body end) of the ga script does not matter as it is loaded and ran before the user can click something, independently.