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

前端 未结 2 1623
无人及你
无人及你 2021-01-31 11:22

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.         


        
相关标签:
2条回答
  • 2021-01-31 11:50

    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.

    0 讨论(0)
  • 2021-01-31 11:54

    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.

    0 讨论(0)
提交回复
热议问题