I'm trying to add to my analytics - i need to be able to monitor some outbound links - got the information i need from google :
http://support.google.com/analytics/answer/1136920?hl=en-GB
and I've implemented the code in root.head.cshtml
<script type="text/javascript">
function trackOutboundLink(link, category, action) {
try {
_gaq.push(['_trackEvent', category , action]);
} catch(err){}
setTimeout(function() {
document.location.href = link.href;
}, 100);
}
</script>
then called the function in my link (the link is included via the editor for the product description) like so :
<a href="http://www.example.com" onClick="trackOutboundLink(this, 'Outbound Links', 'example.com'); return false;" target="_blank">
All the code renders fine in the page that's delivered to the browser.
But this isn't registering on my analytics - anyone know why/why not ? am I not waiting long enough for the results to be recorder or is there a problem ?
also, despite including target="_blank" the new link opens up in the same page.
Any ideas would be much appreciated.