[cross-posted on a Google Products Forum]
Currently, I have implemented the code from this website.
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript'>
function recordOutboundLink(link, category, action) {
try {
var myTracker=_gat._getTrackerByName();
_gaq.push(['myTracker._trackEvent', category , action ]);
setTimeout('document.location = "' + link.href + '"', 100)
}catch(err){}
}
</script>
I directly copied this code from here.
However, when I add
onClick="recordOutboundLink(this, 'Outbound Links', 'Postdoc advert');return false;"
to some links, it doesn't seem to track any clicks. I have searched online for a solution but none of them seem to work.
Can someone point out what mistake I might be making?
P.S. I found a similar complaint online at this forum post, which suggests that the code is malfunctioning.