Categories: Discuss Tracking and Implementation issues :

recordOutboundLink doesn't work

Showing 1-1 of 1 messages
recordOutboundLink doesn't work s_loszewski 10/24/12 2:13 PM
I found this function in Google documentation for tracking outbound links:


<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>

It doesn't work. when you do the call to _getTrackerByName(), it returns a tracker with account id: UA-XXXXX-X. It should return the the default tracker. So it doesn't record any events because it doesn't have an account number. I know there's a default tracker in my code because it records the pageviews - just doing the regular script, nothing fancy:

<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'MYACCOUNTNUMBER]); _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>

That documentation should be taken down or fixed. This works if you're just using the default tracker:

<script type="text/javascript">
function recordOutboundLink(link, category, action) {
try {
_gaq.push(['_trackEvent', category , action ]);
setTimeout('document.location = "' + link.href + '"', 100)
}catch(err){}
}
</script>
</head>