Google Analytics works by the inclusion of a Javascript file on pages in your website. This Javascript file contains tracking code that executes when visitors request your website pages. The tracking code performs, among other things, two critical actions:
These two operations determine how your reporting data is collected. Both the request of the image and the setting of cookies are impacted by different website configurations, so it's a good idea to understand the general process to ensure that your reports deliver data as you expect. The rest of this document covers:
In general, the Google Analytics Tracking Code (GATC) retrieves web page data as follows:
__utm.gif, and appends to the image request a long list of parameters containing tracking information.
The example above also illustrates a customization to the tracking code in order to track visitor interaction between two related sites (site linking). This is accomplished by using the function _setAllowLinker(). A default installation of the tracking code would not include such a function, but this and many more are available for you to use in order to customize the tracking code should your setup need it. For more information on the customization functional available in the Google Analytics Tracking Code, see the API reference.
The tracking code is designed to read data from your page after the content for the page has finished loading. The diagram above illustrates the recommended structure for your tracking code, such that the snippet appears just before the closing </body> tag for your web page. Once the content for your page has loaded, the tracking code, when executed, reads the content for your page following the Document Object Model (DOM). All information relevant to tracking is then used to establish page information, set/update cookies, and to send the GIF request to the Google Analytics servers.
By placing the script at the end of the page body, you ensure that the tracking code is executed as the last element of the DOM. If a given page load is interrupted for some reason, it is possible that the GIF request for that page view will not be executed. However, should you place the tracking code at the top of the page, any load interruptions might result in incomplete or inaccurate reporting anyhow, since the tracking code relies on page data for its reports. Additionally, the physical placement of the tracking code call at the bottom of the page is more effective than using an onLoad() function to call the tracking code. If you use onLoad() to execute the tracking code, execution relies on the event model for the browser instead of the DOM. In such a situation, should a remote image fail to load on a page, onLoad() will not be called, whereas the DOM could still load completely.
Each time the Google Analytics Tracking Code executes, it requests a single-pixel GIF image from the Google Analytics collection servers called __utm.gif. Appended to the request string for the image are all the parameters Google captures about a particular page request, including:
The data contained in the GIF request is the data sent to the Google Analytics servers, which then gets processed and ends up in your reports. Consequently, if there is missing data that you expect in your reports, this data will also be missing from the GIF request. Here is an example of only a part of a GIF request:
http://www.google-analytics.com/__utm.gif?utmwv=4&utmn=769876874&utmhn=example.com&utmcs=ISO-8859-1&utmsr=1280x1024&utmsc=32-bit&utmul=en-us&utmje=1&utmfl=9.0%20%20r115&utmcn=1&utmdt=GATC012%20setting%20variables&utmhid=2059107202&utmr=0&utmp=/auto/GATC012.html?utm_source=www.gatc012.org&utm_campaign=campaign+gatc012&utm_term=keywords+gatc012&utm_content=content+gatc012&utm_medium=medium+gatc012&utmac=UA-30138-1&utmcc=__utma%3D97315849.1774621898.1207701397.1207701397.1207701397.1%3B...
The file is delivered to the user's browser, which is a single-pixel image. The URL for the file contains a set of query string parameters derived from the tracking code initialization and is stored on the log files. Typically, this GIF file is located on the Analytics website, but the GIF request for users of the stand-alone Urchin software typically refers to a local server.
For more information on the data contained in a GIF request, see the section "GIF Request Parameters" in the Troubleshooting Guide.