title: Avoiding race conditions in Google Analytics asynchronous tracking
body: <p>I am having issues with many of my events (maybe 20%) not getting recorded in Google Analytics.  These are all events called with onclick on an image button that posts a form.  I believe that the code isn't running fast enough to submit the events to Google before the browser moves on to the next page.</p>
  
  <p>What I would like to do is check the state of _gaq's queue and make sure there are no pending events before completing my Javascript.</p>
  
  <p>_gaq seems a little cryptic to me, but it does have an exposed property - u.  I've been testing in Chrome with a simple command of:</p>
  
  <pre><code>console.log(_gaq.u);
  </code></pre>
  
  <p>Unfortunately, this always returns 0, even if run immediately after the _gaq.push command.  Of course, Chrome always seems to get the events sent to Google before the post fires, so I'm not sure if I even can debug in Chrome, since I can't replicate the problem.</p>
  
  <p>Does anyone know if there is a way to get the count of pending items in the queue from _gaq?  Is _gaq.u the appropriate property?  I would like to do something a little more elegant than just throwing a 100 or 200 ms wait on all my events.</p>