为什么Google Analytics使用单像素图片来传输数据?

发布于 2024-12-03 09:27:27 字数 698 浏览 0 评论 0原文

Google Analytics(分析)嵌入了一个带有如下 URL 的单像素 GIF:

http://www.google-analytics.com/__utm.gif?utmwv=5.1.5&utms=5&utmn=1532897343&utmhn=www.douban.com&utmcs=UTF-8&utmsr=1440x900&utmsc=24-bit&utmul=en-us&utmje=1&utmfl=10.3%20r181&utmdt=%E8%B1%86%E7%93%A3&utmhid=571356425&utmr=-&utmp=%2F&utmac=UA-7019765-1&utmcc=__utma%3D30149280.1785629903.1314674330.1315290610.1315452707.10%3B%2B__utmz%3D30149280.1315452707.10.7.utmcsr%3Dbiaodianfu.com%7Cutmccn%3D(referral)%7Cutmcmd%3Dreferral%7Cutmcct%3D%2Fgoogle-analytics-architecture.html%3B%2B__utmv%3D30149280.162%3B&utmu=qBM~

为什么不使用 AJAX 调用?使用单像素 GIF 有什么好处?

Google Analytics embeds a one pixel GIF with a URL like this:

http://www.google-analytics.com/__utm.gif?utmwv=5.1.5&utms=5&utmn=1532897343&utmhn=www.douban.com&utmcs=UTF-8&utmsr=1440x900&utmsc=24-bit&utmul=en-us&utmje=1&utmfl=10.3%20r181&utmdt=%E8%B1%86%E7%93%A3&utmhid=571356425&utmr=-&utmp=%2F&utmac=UA-7019765-1&utmcc=__utma%3D30149280.1785629903.1314674330.1315290610.1315452707.10%3B%2B__utmz%3D30149280.1315452707.10.7.utmcsr%3Dbiaodianfu.com%7Cutmccn%3D(referral)%7Cutmcmd%3Dreferral%7Cutmcct%3D%2Fgoogle-analytics-architecture.html%3B%2B__utmv%3D30149280.162%3B&utmu=qBM~

Why not use an AJAX call? What's the benefit of using a one-pixel GIF?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

后来的我们 2024-12-10 09:27:27

因为您无法真正执行跨域 AJAX(CORS 除外,但这是一个不同的故事,并且是最近出现的现象,支持程度不高。)AJAX 适用于同源请求。此外,Google Analytics 是从 Urchin 分叉的,它实际上早于 AJAX 技术的采用。

请求图像是分析服务“请求”某些内容作为将某些内容发送到第三方服务器的一种相当标准的做法。 AJAX/CORS 没有真正意义的原因是,您实际上并没有请求在页面上使用的重要资源,因此您希望请求本身尽可能快且开销更少。

分析服务偶尔处理从客户端发送数据的另外两种方式是:

  1. 包括一个不可见的 iframe,其中 iframe src 上的查询字符串传递分析数据

  2. 请求图像,而不是返回图像,而是返回带有 HTTP 的空响应204 标头

Because you can't really do cross domain AJAX (with the exception of CORS, but that's a different story, and a recent phenomenon with less than universal support.) AJAX is for same origin requests. Also, Google Analytics forks from Urchin, which actually predates AJAX technology's adoption.

Requesting an image is pretty standard practice for analytics services "requesting" something as a means of sending something to a third party server. The reason AJAX/CORS doesn't really make sense is that you're not actually requesting an important resource for use on the page, so you want the request itself to be as quick and overhead-less as possible.

The other two ways analytics services occasionally handle sending data from the client is:

  1. Including an invisible iframe, with the query string on the iframe src passing the analytics data

  2. Requesting an image, and instead of returning an image, returning an empty response with a HTTP 204 header.

辞取 2024-12-10 09:27:27

以最大限度地提高兼容性。例如,手机浏览器可能不支持 AJAX,因此可能提供不充分的结果。但是,嘿,谷歌做了很多没人能解释的时髦的事情。

To maximize compatability. A cell phone browser may not support AJAX, for example, and thus may provide inadequate results. But hey, Google does a lot of funky stuff that nobody can explain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文