Google Analytics - Where and why to implement correctly?

72 views
Skip to first unread message

Devsupport@CTM

unread,
Aug 17, 2011, 4:18:40 AM8/17/11
to google-analytic...@googlegroups.com

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:

http://code.google.com/apis/analytics/docs/tracking/gaTrackingOverview.html

 

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

http://www.google.com/support/analytics/bin/answer.py?hl=en_US&answer=174090&utm_id=ad

Nick

unread,
Aug 22, 2011, 10:31:56 PM8/22/11
to google-analytic...@googlegroups.com
Hi.

This is completely the wrong forum for tracking code discussion. You should really ask in the general user forums: http://www.google.com/support/forum/p/Google+Analytics/?hl=en

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.

-Nick
Reply all
Reply to author
Forward
0 new messages