Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Google Analytic request a GIF file?

Why does Google Analytic request a GIF file?

Is it because the GIF allows access to more data than JavaScript alone. Is it to get the IP address of the user?

like image 766
alex Avatar asked Jan 17 '10 23:01

alex


People also ask

Does Google Analytics send data to Google?

Google Analytics Measurement ProtocolWith Universal Analytics, we can now send data into Google Analytics from any internet-enabled device by simply following a specific set of instructions, called the Measurement Protocol.

How do you send a Google Analytics request?

If you receive a link to Analytics data, for example, to a report or dashboard, and you don't have access to the account, you can request access. When you click the link, then click Request access to send an email request to administrators of the Analytics account.


1 Answers

Google's javascript has to transmit the details of your page view to their servers some how. Ajax cannot be used across domains, so the only way to submit the information is to request a file from a Google server, passing the necessary information in the query string. To facilitate this, some form of content must be requested using a standard HTML tag. The easiest way to do this without impacting the page itself is to load a 1x1 transparent gif. Note that in the case of the Google script (and others), this image isn't actually added to the page. It's merely loaded via a javascript statement

var img1 = new Image();
img1.src = 'http://path/to/file.gif?otherinfohere';

This loads the image without adding it to the page. The information could also be loaded using a script tag like so:

<script src="http://path/to/script.js?otherinfohere" type="text/javascript"><script>

However, users are more likely to have javascript blocked than images, so the safer route is to request an image. As to why they would use a gif instead of say, a jpg, a gif is safer in case a rogue browser actually adds the image to the page. The transparent gif is unlikely to negatively impact the layout, where as a 1x1 jpg would leave a 1 pixel dot somewhere on the page.

Edit: To add to my comment about users having blocked javascript, a gif request containing static information can be added inside a noscript tag to allow basic tracking even in the event that javascript is disabled. To my knowledge, GA doesn't do this, but some other web analytics providers do.

like image 79
Chris Avatar answered Jan 04 '23 09:01

Chris