Google Analytics 应该放在 HTML 页面的头部还是底部? [英] Should Google Analytics go in the head or bottom of an HTML page?

查看:17
本文介绍了Google Analytics 应该放在 HTML 页面的头部还是底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google 建议在关闭 </head> 之前放置 google 分析脚本.

Google advises putting the google analytics script right before closing the </head>.

但是,我更愿意将它与我的 javascript 的其余部分结合在一起,这些 javascript 现在都在一个缓存的外部文件中,该文件加载在我的 HTML 文件的底部.我可以按我的方式做吗?如果是这样,那么我要冒什么风险/将下面的代码放在 HTML 的底部而不是头部的成本是多少?

However, I would prefer to combine it with the rest my javascript that are now all together in a cached, external file, which is loaded at the bottom of my HTML file. Can I do it my way? If so, what am I risking then/what's the cost of putting the below code not in the head but at the bottom of the HTML?

<script type="text/javascript">
 var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-22180365-1']);
  _gaq.push(['_setDomainName', 'none']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

推荐答案

你真的没有冒任何风险.建议将

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