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?
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']);
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.