3 ms·
The author is ignoring that: A) Most sites do have content with which async GA can load in parallel. B) Where you put the GA snippet is a trade-off. Putting
by enomar 17y ago
The author is ignoring that:
A) Most sites do have content with which async GA can load in parallel.
B) Where you put the GA snippet is a trade-off. Putting after window.onload will decrease the time it takes to get to window.onload, but it will also lessen the accuracy of your data; especially your bounce rate.
C) If you're worried about delaying user visible functionality that is tied to window.onload, you shouldn't be tying that functionality to window.onload in the first place. There are better ways to detect when the DOM is ready to use.
- stanleydrew 17y agoWith respect to (C), can you describe some other good DOM-readiness detection methods?
- enomar 17y agohttp://dev.jquery.com/browser/trunk/jquery/src/event.js#L802 http://dev.jquery.com/browser/trunk/jquery/src/event.js#L802
- superjared 17y agoMooTools' DomReady is a great example: http://mootools.net/docs/core/Utilities/DomReady http://mootools.net/docs/core/Utilities/DomReady
- daleharvey 17y agoput the script at the bottom of the page I never understood why onload and all the frameworks implementing domloaded exist, script tags generally should go at the end anyway, and there is no problems with dom availability.
- 124816 17y agoThis is fine, if you're OK with missing bounces. If the page takes a long time to load, or hangs, then it's likely the user will close the window before the script runs.
- enomar 17y agoI don't think he was necessarily suggesting putting GA at the bottom of the page. I read this as, "put the DOM ready detection" at the end of the page.
- enomar 17y agoWhen you're writing a third party script you don't have control over where in the page someone will put it. Having code to detect DOM ready is useful in these cases.