0

I have heard from different sides, that Google Analytics Event Tracking is failing often on onklick triggering like this:

<a href="#somelink" onclick="EventTrackingCode">

because Browsers may are to fast for tracking by loading the target faster than ga event tracking was fired.

So my Question is, does it matter to do tracking with jQuery Events and not with onklick triggers? Any experiences so far?

Viktor
  • 623
  • 4
  • 10
  • 25
  • ok, onMouseDown seems to be a solution: http://www.cardinalpath.com/experiment-onclick-vs-onmousedown-event-tracking-in-google-analytics/ – Viktor May 08 '14 at 12:58

2 Answers2

1

You are right - on outbound links the _gaq code will often not enough time to process before the browser unloads your page and loads the new site. If the link is internal, and the page you are going to has the GA script, then it should work fine, because GA queues the event and sends in on the next page.

So, the problem is really with outbound links and the onclick function.

To solve this problem, use the GA Hit Callback

Google documentation includes and example of using Hit Callback for Outbound Links. There is also a good discussion of this on StackOverflow from back in Sep 2012 which shows how to implement Hit Callback in traditional GA as well as Universal Analytics: Use Google Analytics hitCallback.

Community
  • 1
  • 1
Mark Hansen
  • 1,044
  • 10
  • 15
  • Do you have any experiences with that? That would make my question irrelevant for me. "If the link is internal, and the page you are going to has the GA script, then it should work fine, because GA queues the event and sends in on the next page." – Viktor May 12 '14 at 12:15
  • @Viktor Yes, I do have experience with it. Just make sure that your GA tracking code is correctly installed on the page you are linking to then the Hit Callback is not necessary and the event should be recorded. Is it not working for you? – Mark Hansen May 12 '14 at 14:42
  • I am not sure if the events hits are counted properly, because if, i do have a noticeable difference between my event and site hits. – Viktor May 13 '14 at 10:06
0

You can also use the JavaScript setTimeout function and delay the firing.

setTimeout(function() {

   if (typeof _gaq != 'undefined') {
      _gaq.push(['_trackEvent', 'Add', name, code, price, false]);
   }

}, 1000);
crmpicco
  • 16,605
  • 26
  • 134
  • 210
  • That is not the question. _gaq is loaded at the time the event is fired – Viktor May 09 '14 at 15:48
  • Yes, don't focus on the `typeof` condition. The `setTimeout` will help you here as it will wait 1 second before firing. Look into it - it helped me out when I had a similar issue. – crmpicco May 09 '14 at 16:02