Google Analytics - Where and why to implement correctly?

已查看 72 次
跳至第一个未读帖子

Devsupport@CTM

未读,
2011年8月17日 04:18:402011/8/17
收件人 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

未读,
2011年8月22日 22:31:562011/8/22
收件人 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
回复全部
回复作者
转发
0 个新帖子