Mobile app version of vmapp.org
Login or Join
Sue5673885

: 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

@Sue5673885

Posted in: #GoogleAnalytics #Html #Javascript

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([&#39;_setAccount&#39;, &#39;UA-XXXXXXX-X#39;]);
_gaq.push([&#39;_trackPageview&#39;]);

(function() {
var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://ssl&#39; : &#39;http://www&#39;) + &#39;.google-analytics.com/ga.js&#39;;
var s = document.getElementsByTagName(&#39;script&#39;)[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?

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Sue5673885

3 Comments

Sorted by latest first Latest Oldest Best

 

@Mendez628

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.

10% popularity Vote Up Vote Down


 

@BetL925

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.

10% popularity Vote Up Vote Down


 

@Angela700

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']);

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme