<head> 中。<head> 中。将它放在 <head> 中的主要优点是你可以跟踪用户的pageview,即使他们在完全加载之前离开页面。
关于我们的选择,这是来自Mathias Bynens的简单引用。
I should point out that it’s Google — not me — recommending to place this
script before all other scripts in the document. The only real advantage is to
catch a pageView call if your page fails to load completely (for example, if
the user aborts loading, or quickly closes the page, etc.). Personally, I
wouldn’t count that as a page view, so I actually prefer to place this script
at the bottom, after all other scripts. This keeps all the scripts together and
reinforces that scripts at the bottom are the right move. (Usually I
concatenate and minify all my scripts into one .js file — the GA snippet being
the suffix.)
译:我应该指出,Google - 而不是我 - 建议将此脚本放在文档中的所有其他脚本之前。 唯一真正的优点是如果您的页面无法完全加载(例如,如果用户中止加载或快速关闭页面等),则可以捕获pageView调用。 就个人而言,我不会将其视为页面视图,所以我实际上更喜欢在所有其他脚本之后将此脚本放在底部。 这将使所有脚本保持一致,并强化底部的脚本是正确的。 (通常我将所有脚本连接起来并将其缩小为一个.js文件 - 作为后缀的GA代码段。)
这是Nicolas Gallagher写的关于HTML5 Boilerplate和Bootstrap如何相互补充的内容。
不需要,这和一旦房子建成,你通常不会改造房子的地基一样。但是,没有什么能阻止你尝试最新的改变,但你必须评估这样做的成本/收益。
在StackOverflow上请求帮助。