Ros Ros - 2 months ago 15
Javascript Question

Google Analytics - Record Outbound Links - open new window

I have used the following link to record outbound links through google analytics. Is it possible to open the link in a new window?

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

<a href="http://www.example.com" onClick="recordOutboundLink(this, 'Outbound Links', 'example.com');return false;">

Answer

edit, I forgot to add target="_blank":

I would do it this way tracking outbound links:

<a href="http://outgoinglink.com" target="_blank" onclick="_gaq.push(['_trackEvent','outgoing_links','outgoinglink.com'])">Link Text</a>