Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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:

GA events page

Could anybody help me? Am I doing anything wrong?

share|improve this question

migrated from stackoverflow.com Jun 16 '12 at 5:53

This question came from our site for professional and enthusiast programmers.

    
have you searched SO? stackoverflow.com/questions/2329566/… –  gorelative Jun 15 '12 at 13:43
    
first answer is for older GA versions in that thread, second answers is basically what I am doing, with no results. Besides, no answers on that thread has been accepted as valid, so what thread? –  the_archer Jun 15 '12 at 13:59
    
How, specifically, did you add the code: Did you add this in the original template/code of the widget? Did you add the onClick-event by your own JS code after page initialization? –  initall Oct 14 '12 at 21:01

3 Answers 3

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.

share|improve this answer

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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.