: Is there any benefit of Google Analytics asynchronous tracking code if it isn't placed in the ? I'd like to go to the asynchronous Google Analytics script, but I'd rather not have it in the
I'd like to go to the asynchronous Google Analytics script, but I'd rather not have it in the head (even though I know this is best practice).
So, is there any benefit of using the async code if it isn't in the head, and alternatively, would it be safe to place elsewhere high in the page, like just inside the opening body tag, or in a .NET user control that loads at the top of the page?
EDIT:
In the instructions Google states:
If that isn't an option, you can still put the asynchronous snippet at the bottom of the page. You can also split your snippet to retain some of the benefits of asynchronous tracking.
If I place the code there (without splitting) do I still benefit from asynchronous loading or is it negligible since it is at the bottom anyway?
More posts by @Murray432
3 Comments
Sorted by latest first Latest Oldest Best
You can add your analytics code anywhere on your page. Google is smart enough to identify / register all events on your page. When you are talking about async there is no point thinking about its in-line/sync placement.
I have used it at bottom for most of my sites and have found no issues.
The main load events that you get in your google analytics account:
1) Dom load time
2) Page load time
This takes into consideration everything and are independent of where you add your code.It might be possible(with sync code) that these time are calculated on basis of Google script position on page as in :
DOM load time - > time of firing dom load event of browser - GA script loading/event
Page load time - > time of firing window load event of browser - GA script loading/event
If this is the case then script position would play a small role in changing above time to more accurate once else i don't think it make much difference.(as placing it on top brings the page with GA prior to placing it at bottom because page loads sequentially)
Compared to having the old tracking code at the bottom of the page, having the asynchronous code at the top of the <body> should still mean that the tracking is more likely to register users who leave the page (or interact with elements on the page that are being tracked) before it has fully loaded.
You can put it anywhere you just get the most benefit from putting it in the header. The full instruction to add it to your web page are here - code.google.com/apis/analytics/docs/tracking/asyncTracking.html.
You do want to put it inside of the head or body tags though. Just to be clear. But beyond that you can do whatever you want.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.