: 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
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>
More posts by @Merenda212
1 Comments
Sorted by latest first Latest Oldest Best
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/
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.