0

I've a very basic tracking event tied to my login button that's working correctly in Chrome and IE but not in Firefox (v26)

_gaq.push(['_trackEvent', 'Navigation', 'Log In', 'Log In button']);

When a user clicks the login button, their request is authenticated via an Ajax call to the server, if the server responds with a success message, then the this GA code is triggered.

No error is reported to the console.

Is there a way to find out if the code fired correctly? Or to know if _gaq has initialised correctly?

Boaz
  • 19,892
  • 8
  • 62
  • 70
ShaneH
  • 385
  • 3
  • 17
  • Does real-time reporting in Analytics show anything going on when you fire the event? – Jared Eitnier Jan 27 '14 at 15:56
  • Nothing shows in the real time report when in Firefox, in Chrome/IE I can see the event – ShaneH Jan 27 '14 at 15:58
  • Is there a redirect taking place once the request is authenticated? – Boaz Jan 27 '14 at 15:59
  • Yes, the basic flow is User click -> $.ajax -> success{ _gaq.push(); someLogic(); redirect; } – ShaneH Jan 27 '14 at 16:02
  • check this out: https://developers.google.com/analytics/resources/articles/gaTrackingTroubleshooting. Maybe download Live http headers for firefox to see what's happening. – Jared Eitnier Jan 27 '14 at 16:04
  • 1
    Sometimes the redirect is taking place before the tracking event has actually loaded. Try adding a slight delay before redirecting. – Boaz Jan 27 '14 at 16:08

2 Answers2

3

Use the Google Analytics built-in hitCallback function:

So, on success:

_gaq.push(['_set', 'hitCallback' , function(){
 //default action
}]);

_gaq.push(['_trackEvent', 'Navigation', 'Log In', 'Log In button']);
Community
  • 1
  • 1
Blexy
  • 9,573
  • 6
  • 42
  • 55
  • Thanks, I've more than one tracker which complicates things. (_gaq.push(['b._trackEvent'... etc.) So if I need to use things like _gaq.push(['b._set','hitCallback'... then the original setTimeout solution is better for me I think even though yours is a better answer to the question – ShaneH Jan 28 '14 at 10:21
2

Thanks to @Boaz I introduced a delay (50ms) after the GA code fires.

_gaq.push(['_trackEvent', 'Navigation', 'Log In', 'Log In button']);

var timeout = 1;
if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1)
    timeout = 50;

setTimeout(function() {
    //redirect
}, timeout);

Event then fired correctly

ShaneH
  • 385
  • 3
  • 17
  • Now that you've debugged the issue, @Blexy method seems to be the most reliable way to overcome it. – Boaz Jan 27 '14 at 18:26