: Tracking Outgoing Links With Google Analytics Events I've been trying to track clicks on external links on my website using the events tracking method. So I've got my Google Analytics code setup
I've been trying to track clicks on external links on my website using the events tracking method.
So I've got my Google Analytics code setup before body ends as shown below (note: quotes have been entitied by blogger, but it works fine):
<script type='text/javascript'>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-X#39;]);
_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>
Now I wanted to track a link on the addthis.com follow widget. So there is a link of the type below to which following instructions from here I added the onclick event.
<a addthis:url='http://feeds.feedburner.com/myfeedburnerlurl' onClick="_gaq.push(['_trackEvent', 'Subscription Clicks', 'RSS']);" class='addthis_button_rss_follow'/>
I clicked on it a couple of times, left it for over a day now, but nothing shows up in google analytics events. It just says zero events. Here's a screenshot of the events page on GA:
Could anybody help me? Am I doing anything wrong?
More posts by @Sue5673885
3 Comments
Sorted by latest first Latest Oldest Best
It's odd to see 0 events here. But assuming you loaded the analytics script correctly... you have three decent options:
1) use onmousedown instead of onclick. This will get you more events but is still not perfect.
2) add a target attribute to your links so the current document doesn't get blown away before the tracking gif can be sent (e.g. ...). This will get you all the events but sometimes loading in another window is undesirable.
3) use hitCallback to be notified when the event has been sent to Google. e.g.
<a onclick="return track('http://example.com');" href="http://example.com">
function track(destination) {
var redirect = function(){ window.location = destination; };
_gaq.push(['_trackEvent', 'outbound', destination]);
_gaq.push(['_set','hitCallback',redirect]);
setTimeout(redirect, 1000); // In case GA fails (trust me, it will eventually)
return false;
}
I've found that option #2 is the best way to get the most events. But in practice, I use #3 the most.
If you are using Google Chrome, you can install the GA Debug Extension. With its help you can see all events that get fired from your website in the Developer Tools Console. This helps you to track down where this error might come from.
You shouldn't have to make changes to your ga tracking snippet, it looks like it has some characters in there that don't belong. I would get a fresh copy from your Google Analytics profile and replace the one on your site
The Google Analytics code I use is below which looks like you're as well. It could be your tracking snippet. I would also verify by placing the event tracking on a standard though the one below works on input form fields as well so it shouldn't matter
onclick="_gaq.push(['_trackEvent', 'Site wide', 'View Cart', 'Top right link']);
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.