问题描述
Google Analytics嵌入了一个像素的GIF,其URL如下所示:
http://www.google-analytics。 COM / __ utm.gif utmwv = 5.1.5&安培; UTMS = 5&安培; utmn = 1532897343&安培; utmhn = www.douban.com&安培; utmcs = UTF-8和; utmsr = 1440&安培; utmsc = 24比特及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(引荐)%7Cutmcmd%3Dreferral%7Cutmcct%3D%2Fgoogle-分析-architecture.html%3B% 2B__utmv%3D30149280.162%3B& utmu = qBM〜
为什么不使用AJAX调用?使用单像素GIF的好处是什么?
因为您无法真正跨域AJAX的CORS,但这是一个不同的故事,而最近的现象并不具有普遍的支持。)AJAX针对的是相同的原始请求。此外,谷歌分析从Urchin中分出,实际上早于AJAX技术的采用。
请求图片是分析服务请求某种东西作为向第三方服务器发送内容的手段的非常标准的做法。 AJAX / CORS没有意义的原因是您实际上并未要求在页面上使用重要的资源,所以您希望请求本身尽可能快速且开销更少。
另外两种分析服务偶尔处理从客户端发送数据的方式是:
-
包含一个不可见的iframe,iframe src上的查询字符串传递分析数据
-
请求图像,而不是返回图像,通过返回空的响应。
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?
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:
Including an invisible iframe, with the query string on the iframe src passing the analytics data
Requesting an image, and instead of returning an image, returning an empty response with a HTTP 204 header.
这篇关于为什么Google Analytics使用一个像素的图片来传输数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!