I am trying to understand how this would ever work:
_gaq = _gaq || [];
_gaq.push(['trackEvent', 'something', 'bleee']);
Ok, so i get it, i am pushing data into some magic array. But how does google’s script know that i have done this? It must either be polling this array (unlikely), or it does something with it when user navigates away from the page.
I have found that making requests when navigating away from the page usually results in the connection being closed before the request completes.
Can someone explain to me how this magic works?
Google has created their own object with a custom
.push()method. So when you push something onto the “array” it activates more code (a function) that creates a tracking pixel and wallah.Google did this so that if you attempt to use the push method of the
_gaqarray before the G.A. snippet has been evaluated, you’re just creating a queue of commands to send to Google (in a standard array). If the G.A. snippet has already been evaluated then you’re actually running a custom function that Google created to replace the.pushmethod.