google-analytics - Universal Analytics 跟踪代码应该放在页面中的什么位置?

标签 google-analytics universal-analytics

我的网站目前在正文底部有传统(非异步)Google Analytics 跟踪代码。

<script type="text/javascript">            
    var gaJsHost = (("https:" == document.location.protocol) ? "https://" : "http://");
    document.write(unescape("%3Cscript src='" + gaJsHost + "stats.g.doubleclick.net/dc.js' type='text/javascript'%3E%3C/script%3E"));           
</script>

我计划升级到 Universal Analytics 跟踪代码。新的跟踪代码可以放入正文中还是应该按照 Google 的规定仅放置在头部(就在标签之前)? 谢谢。

最佳答案

Google 在 Set up the web tracking code 中表示

Paste your snippet (unaltered, in it’s entirety) into every web page you want to track.
Paste it immediately before the closing </head> tag. If you use templates to 
dynamically generate pages for your site (like if you use PHP, ASP, or a similar
technology), you can paste the tracking code snippet into its own file, then include
it in your page header.

我知道有人将其放在正文中以及页面底部,所以是的,如果您愿意,您可以将其放入正文中。它仍然会起作用。就我个人而言,我总是把它放在标题中,如果谷歌推荐它,他们必须知道他们在说什么。

关于google-analytics - Universal Analytics 跟踪代码应该放在页面中的什么位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23903720/

相关文章:

javascript - Google Analytics 事件工作不一致

google-analytics - 如何在 Google Analytics 仪表板小部件上按日期过滤

google-analytics - 为多环境设置集成 GTM 查找表的问题

javascript - 多个跟踪器和电子商务集成失败 - Google Analytics

google-analytics - 谷歌分析 : Test event tracking with test profile

javascript - 使用构造函数/Universal Analytics 立即调用函数

javascript - 使用客户端 ID 获取用户信息

google-analytics - 我们可以在内部网站上使用谷歌分析吗?

javascript - 如何在谷歌分析中跟踪 iPhone 方向?

google-analytics - ga :screenDepth in the GA4 data api? 相当于什么