I want to push two events in a function.My code goes somewhat like this-
function track(){
_gaq.push(['_trackEvent', 'Search', 'Search Attempt','User searched for a username']);
//few more lines of code before an ajax call
$.ajax({
url : '/xyz.json'
,type : 'POST'
,data : "uname="+uname
,dataType : 'json'
,success : function(data) {
if(data.success) {
_gaq.push(['_trackEvent', 'Search', 'Search Success','User found user with username searched']);
window.location.href='/thread/'+uname;
}
});
}
The problem that I am facing is that, the first event gets tracked but the other one with the if condition after the json call does not gets tracked.However "window.location.href" redirects me to the new url.
Also there is a case when I push this-
_gaq.push(['_trackEvent', 'Search', 'Search Attempt','User searched for a username'],
['_trackEvent', 'Search', 'Search Success','User found user with username searched']);
In this case, only first event gets tracked. (Both the cases work properly sometimes, where could be the problem then?