我应该将Google Analytics JS放在< head>或者在< body>的结尾处? [英] Should I put the Google Analytics JS in the <head> or at the end of <body>?

查看:112
本文介绍了我应该将Google Analytics JS放在< head>或者在< body>的结尾处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google给了我一段javascript,并告诉我将它包含在< head> 中。



我可以把它放在< body> 的末尾,否则会出现一些副作用?

< head> 部分的末尾有助于确保您的指标即使在用户不'让页面完成加载。



他们曾经告诉你在页面底部放置它,然后再添加对部分加载页面的支持。 p>

直接来自Google:



的主要优点之一异步片段是,您可以
将它放在HTML
文档的顶部。这增加了
跟踪信标
将在用户离开
页面之前发送的可能性。习惯上将
JavaScript代码放在< head> 部分中,
,我们建议将代码片段
放在底部

请参阅 Google Analytics帮助将跟踪代码直接添加到您的网站中


Google gives me a piece of javascript and tells me to include it in the <head>.

Can I put it at the end of <body> or will some side effects occur if I do that?

解决方案

Putting it at the end of the <head> section helps ensure the your metrics are tracked even when a user doesn't let the page finish loading.

They used to tell you to put it at the bottom of the page, before they added support for handling partial loading of pages.

Directly from Google:

One of the main advantages of the asynchronous snippet is that you can position it at the top of the HTML document. This increases the likelihood that the tracking beacon will be sent before the user leaves the page. It is customary to place JavaScript code in the <head> section, and we recommend placing the snippet at the bottom of the section for best performance.

See Google Analytics Help: Add the tracking code directly to your site

这篇关于我应该将Google Analytics JS放在&lt; head&gt;或者在&lt; body&gt;的结尾处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆