Mobile app version of vmapp.org
Login or Join
Merenda212

: How to track outbound links in Google Analytics? I'm having trouble tracking outbound links from my page. I can see the visits to the page in Google Analytics, but still I can't see what I'm

@Merenda212

Posted in: #Analytics #Google

I'm having trouble tracking outbound links from my page. I can see the visits to the page in Google Analytics, but still I can't see what I'm doing wrong (of course I have replaced the UA-XXXX code with my own code).

Can anyone spot anything wrong with the below code?

One interesting thing is that when I include the tracking function in the <head> section, my page doesn't load correctly in Firefox. So, I checked the syntax and all seems ok.

I've added this just before the closing </body> tag:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-XXXX-1");
pageTracker._trackPageview();
} catch(err) {}
</script>


I have this just before the closing </head> tag:

<script type="text/javascript">
function recordOutboundLink(link, category, action) {
try{
var pageTracker = _gat._getTracker("UA-XXXX-1");
pageTracker._trackEvent(category, action);
setTimeout('document.location = "' + link.href + '"', 100);
} catch(err)
{}
}
</script>


This is an example of an outbound link:

<a href="http://www.blahblah.com" title="blah_site" target="_blank" onClick="recordOutboundLink(this, 'My Outbound Links', 'BLAH');return false;">blah site</a>

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Merenda212

1 Comments

Sorted by latest first Latest Oldest Best

 

@BetL925

As the comments suggest, you might want to set the timeout higher. Here is a similar script that uses 400 milliseconds: www.blastam.com/blog/index.php/2013/03/how-to-track-downloads-in-google-analytics-v2/

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme