插入Google Analytics代码的最佳位置 [英] Best place to insert the Google Analytics code

查看:105
本文介绍了插入Google Analytics代码的最佳位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WordPress,页眉或页脚中插入Google Analytics(分析)代码的最佳位置在哪里?我更喜欢footer,因为我希望我的站点通过减少标题中脚本的数量来加快加载速度,但即使脚本在脚注中也可以运行吗?

解决方案

Google过去建议将它放在< / body> 标记之前,因为它们提供的原始方法用于加载 ga.js 被拦截。尽管新的异步语法可以安全地放在最前面,但最小的障碍是,所以当前的建议就在< / head> 标记之前。

< head> 会增加一点延迟;在页脚中会减少一些小页面记录的综合浏览量。这是一个折衷。 ga.js 大量缓存并存在于整个网络的大部分站点上,因此它通常由缓存提供服务,从而将延迟降低到几乎为零。

作为个人偏好,我喜欢将它包含在< head> 中,但它真的一个偏好问题。

Where’s the best place to insert the Google Analytics code in WordPress, header or footer? I prefer footer, because I wanted my site to load faster by reducing the number of scripts in the header, but can it work even if the script is in the footer?

解决方案

Google used to recommend putting it just before the </body> tag, because the original method they provided for loading ga.js was blocking. The newer async syntax, though, can safely be put in the head with minimal blockage, so the current recommendation is just before the </head> tag.

<head> will add a little latency; in the footer will reduce the number of pageviews recorded at some small margin. It's a tradeoff. ga.js is heavily cached and present on a large percentage of sites across the web, so its often served from the cache, reducing latency to almost nil.

As a matter of personal preference, I like to include it in the <head>, but its really a matter of preference.

这篇关于插入Google Analytics代码的最佳位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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