Google Analytics 是否有性能开销? [英] Does Google Analytics have performance overhead?

查看:31
本文介绍了Google Analytics 是否有性能开销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google Analytics(分析)在多大程度上影响性能?

To what extent does Google Analytics impact performance?

我正在寻找以下内容:

  • 基准(包括响应时间/页面加载时间等)
  • 类似基准的链接或结果

在您的网站上测试 Google Analytics (GA) 的一种(可能)方法:

One (possible) method of testing Google Analytics (GA) on your site:

  1. 从您自己的服务器提供 ga.js(Google Analytics JavaScript 文件).
  2. 来自 Google 每日(测试 1)和每周(测试 2)的更新.

我很想知道这如何减少客户端网络服务器和 GA 服务器之间的通信.

I would be interested to see how this reduces the communication between the client webserver and the GA server.

有人做过这些测试吗?如果是这样,你能提供你的结果吗?如果没有,是否有人有更好的方法来测试使用 GA 的性能影响(或缺乏)?

Has anyone conducted any of these tests? If so, can you provide your results? If not, does anyone have a better method for testing the performance hit (or lack thereof) for using GA?

推荐答案

2018 年更新:安装 Analytics 的位置和方式一再发生变化.当前的 gtag.js 代码做了一些事情:

2018 update: Where and how you mount Analytics has changed over and over and over again. The current gtag.js code does a few things:

  1. 加载 gtag 脚本但异步(非阻塞).这意味着它不会以任何其他方式降低您的页面速度,但带宽和处理速度除外.
  2. 在页面上创建一个名为window.datalayer
  3. 的数组
  4. 定义一个小 gtag() 函数,它只是将你扔给它的任何东西推送到该数组中.
  5. 使用页面加载事件调用它.
  1. Load the gtag script but async (non-blocking). This means it doesn't slow your page down in any other way than bandwidth and processing.
  2. Create an array on the page called window.datalayer
  3. Define a little gtag() function that just pushes whatever you throw at it into that array.
  4. Calls that with a pageload event.

主 gtag 脚本加载后,它会将此数组与 Google 同步并监控其更改.这是一个很好的系统,与以前的系统不同(例如在 </body> 之前填充代码)这意味着您可以在 DOM 呈现之前调用事件,并且脚本顺序并不重要,只要你先定义gtag().

Once the main gtag script loads, it syncs this array with Google and monitors it for changes. It's a good system and unlike the previous systems (eg stuffing code in just before </body>) it means you can call events before the DOM has rendered, and script order doesn't really matter, as long as you define gtag() first.

这并不是说这里没有性能开销.我们在加载脚本时仍然使用带宽(它在本地缓存了 15 分钟),而且他们扔给你的不是一小堆脚本,所以有一些 CPU 时间来处理它.

That's not to say there isn't a performance overhead here. We're still using bandwidth on loading up the script (it's cached locally for 15 minutes), and it's not a small pile of scripts that they throw at you, so there's some CPU time processing it.

但与(例如)现代前端框架相比,这一切都可以忽略不计.

如果您要访问绝对精简的网站,请完全避免使用它.如果您想保护用户的隐私,请不要使用任何第三方脚本...但是如果我们谈论的是一个普通的现代网站,那么 悬而未决的结果比如果您遇到性能问题,请使用 gtag.js.

If you're going for the absolute, most cut-down website possible, avoid it completely. If you're trying to protect the privacy of your users, don't use any third party scripts... But if we're talking about an average modern website, there is much lower hanging fruit than gtag.js if you're hitting performance issues.

这篇关于Google Analytics 是否有性能开销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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