Hacker News new | past | comments | ask | show | jobs | submit login

Concat is only called before GA is loaded, so I don't think any race condition could happen.



Only if everyone loads it the same way. But there are lots of different ways to load GA; the only reason _gaq.push() isn't scary and doesn't raise the specter of race conditions is because of the 'spoofing' GA does.

There are LOTS of different versions of the GA snippet floating around the internet; the assumptions this configuration makes would only work for some of them.

For example, some people load GA like this:

     <script async src="//google-analytics.com/ga.js">     </script>
     <script>
     var _gaq = _gaq || [];
     ...
     </script>
Folks who do this will break at minimum with older browsers that don't support async; not sure what it would do with async support, though.

It seems unnecessarily risky.


Ok, now I understand what the issue is. I guess a good solution would be to pass _gaq to my library initializer and push every value with a for cycle, instead of using concat. Thanks for the tip.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: