I have a html5 mobile app where everything exists on a single page and I use history.back/popstate/etc to change the contents of the page (via jQuery Mobile). I'm using Google Analytics to track various events, and on one page I track if the user exits via a particular button:

In the android 2.2 browser history.back() is called but onpopstate is not fired and the page isn't changed. If I put window.onpopstate = function() { alert("!"); }; just before the history.back(), I see no alert.

If I reverse the two lines (history.back() first, then _gaq.push), it seems to work, but I can't rely on this kind of ordering throughout my code.

No exceptions are being thrown. It works fine in iOS and desktop Chrome.

Any ideas why history.back() doesn't work after a google analytics call?

I am having the exact same issue. I don't suppose you've come up with a solution or workaround since first posting this months ago, have you?
– TrottFeb 16 '12 at 0:02

I did not find a workaround sorry. We eventually just stopped using google analytics, and we avoid putting code near history.back().
– DurhamGFeb 16 '12 at 6:32

I can't specifically remember having the same problem, but looking through the JavaScript for a HTML5 app I built (year and half ago now), I delegate calls to Google Analytics through a function that I just call at the end of other functions/calls that need it.
– cchanaMar 12 '12 at 15:09

Does using window.onhashchange in place of window.onpopstate change anything? @RTB
– xdumaineJul 23 '12 at 17:07