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

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

问题描述

在 WordPress、页眉或页脚中插入 Google Analytics 代码的最佳位置在哪里?我更喜欢页脚,因为我希望通过减少页眉中的脚本数量来更快地加载我的网站,但是即使脚本在页脚中它也能工作吗?

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 曾经推荐把它放在 </body> 标签之前,因为他们提供的原始方法用于加载 ga.js 被阻塞.不过,较新的异步语法可以安全地以最少的阻塞放入头部,因此当前的建议正好位于 </head> 标记之前.

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.

会增加一点延迟;在页脚中将减少以很小的幅度记录的浏览量.这是一个权衡.ga.js 被大量缓存并存在于整个网络的大部分网站上,因此它通常从缓存中提供服务,将延迟减少到几乎为零.

<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天全站免登陆