Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Google Analytics use a one-pixel picture to transfer data?

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?

like image 269
Jeffrey Hsu Avatar asked Sep 08 '11 04:09

Jeffrey Hsu


People also ask

What is a Google Analytics pixel?

It's a 1×1-pixel graphic used for tracking user behavior, site conversions, web traffic, and other metrics at a site's server level. In other words, it is a tiny pixel-sized image, usually hidden, embedded in everything, from banner ads to emails.

What's the difference between the results of the Facebook pixel and Google Analytics?

Facebook Pixel vs Google Analytics: Domain While Google Analytics collects user data across different channels such as Organic Traffic, Paid Ads, and Social Media, Facebook Pixel focuses solely on Paid Ads (Facebook and Instagram advertisements).


1 Answers

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.

like image 170
Yahel Avatar answered Oct 23 '22 11:10

Yahel