Kal
Kal

Reputation: 1717

How do I check if _gaq has been emptied?

GA imposes a rate limit of one-hit-per-second on ga.js. If I understand correctly, that means we can _gaq.push very fast all we want, but the queue will just keep growing and only get slowly emptied, one event per second.

Suppose I have a button that makes the browser navigate away. If I'm the paranoiac type, how do I ensure that the _gaq has been emptied before navigating away (otherwise some events don't get the chance to be sent to GA)?

Upvotes: 2

Views: 348

Answers (1)

mike
mike

Reputation: 7177

One possibility -- with ga.js, you can push a function object onto _gaq, that could be used for page navigation. (Update: this won't work for detecting rate limiting)

However... The GA rate limit is for 'hits', i.e. commands sending data to GA. It's not clear how limiting occurs when the limit is reached -- If it's by limiting _gaq command execution then using a function object should work.

Another possibility is to switch to the newer Universal Analytics, which allows for a hitCallback function that runs after the hit has been processed. Also, the rate limit is 20 + 2 hits per second.


Update: I just ran the following test in Chrome, using the developer tools console and network panels:

for (i = 0; i < 20; i++) {
  _gaq.push(['_trackEvent', 'test', 'test', 'test', i]);
  _gaq.push(function() {console.log(i + ': ' + new Date());});
}

The console log shows all 20 timestamps within 1 second. The network log only shows the first 10 tracking image requests.

My interpretation of the test is that GA rate limiting for 'hit' commands works by throwing the data away.

Upvotes: 3

Related Questions