为什么 Google Analytics 使用一像素的图片来传输数据? [英] Why does Google Analytics use a one-pixel picture to transfer data?

查看:24
本文介绍了为什么 Google Analytics 使用一像素的图片来传输数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google Analytics 嵌入了一个带有如下网址的单像素 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~

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

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

推荐答案

因为你不能真正做到跨域 AJAX(CORS 除外,但这是一个不同的故事,而且是最近出现的一种缺乏普遍支持的现象.) AJAX 用于同源请求.此外,Google Analytics 分叉自 Urchin,它实际上早于 AJAX 技术的采用.

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.

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

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. 包含一个不可见的 iframe,iframe src 上的查询字符串传递分析数据

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

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

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

这篇关于为什么 Google Analytics 使用一像素的图片来传输数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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