Google Analytics - Where and why to implement correctly?

Showing 1-2 of 2 messages
Google Analytics - Where and why to implement correctly? Devsupport@CTM 8/17/11 1:18 AM

We have had an interesting discussion whereby the correct implementation of the Google Analytics code was raised. One side had one link with information and the other the other link and information. After reading the two articles it would appear that they conflict and are ambiguous.


Usually we add our analytics code to the bottom of our clients sites just before the closing </body> tag as per the following article:


We have since seen the following article which states that the analytics code should be added to the <head> tag:

Re: Google Analytics - Where and why to implement correctly? Nick 8/22/11 7:31 PM

This is completely the wrong forum for tracking code discussion. You should really ask in the general user forums:

That said, the difference in code placement instructions is in how each example loads the tracking code JavaScript file.

In the gaTrackingOverview doc, the inclusion method will load the JavaScript in a synchronous, blocking, way. This means the entire page will stop loading, until the tracking code has been retrieved from Google's server or from your browser cache. This can be bad if our code doesn't load, and the entire page stops rendering because of it. So the recommendation is to load the script before the end of the body tag, after all the content on your site has loaded. Though using this inclusion mechanism is not a best practice.

Instead we recommend you use the other asynchronous inclusion method, which will load the tracking code in parallel with other content on your page. Because our code will not block other scripts and content from loading, we recommend you call it as soon as you can to get the most accurate data collection.