views:

1102

answers:

5

Yes, I know you have to embed the google analytics javascript into your page.

But how is the collected information submitted to the google analytics server?

For example an AJAX request will not be possible because of the browsers security settings (cross domain scripting).

Maybe someone had already a look at the confusing google javascript code?

+1  A: 

Use the httpfox or firebug Firefox extension to figure out what HTTP requests the browser sends and what responses it receives.

I don't know how Google Analytics works, but one possibility is to make the browser download an image: <img src="http://my-analytics.com" width="1" height="1"> (with a single, transparent pixel), and log all the HTTP request headers (e.g. Referer:) on the server side.

pts
+4  A: 

It's easy enough to tell by using something like Firebug's Net tab.

Ajax isn't needed - since data isn't being fetched from Google. They just encode the information in a query string, and then load a transparent gif using it.

David Dorward
Thats not true, the query string is too short to contain that amount of information. There are only some unique ids and keywords encoded.
echox
Install Fiddler and watch
epascarello
+3  A: 

Without looking at the code, I assume their data is collected from the HTTP headers they receive in the asynchronous request.

Remember that most browsers send data such as OS, platform, browser, version, locale, etc... Also they do have the IP so they can guesstimate your location. And I assume they have some sort of clever algorithm to decide whether you are a unique visitor or not.

Time on the site is probably calculated by using an onUnload() event.

Yuval A
+1 to push you over to 10k ;)
Paolo Bergantino
regarding the onUnload() event, this seems to prove GA doesn't do that: http://groups.google.com/group/analytics-help-troubleshoot/browse_thread/thread/d142572ddf1fa9dd/38dd640f949e9890?pli=1also, go to your GA and check the average time for visits with 1 pageview - it's 0s.
tpk
+8  A: 

When html page makes a request for a ga.js file the http protocol sends big amount of data, about IP, refer, browers, language, system. There is no need to use ajax.

But still some data cant be achieved this way, so GA script puts image into html with additional parameters, take a look at this example:

http://www.google-analytics.com/__utm.gif?utmwv=4.3&amp;utmn=1464271798&amp;utmhn=www.example.com&amp;utmcs=UTF-8&amp;utmsr=1920x1200&amp;utmsc=32-bit&amp;utmul=en-us&amp;utmje=1&amp;utmfl=10.0%20r22&amp;utmdt=Page title&utmhid=1805038256&utmr=0&utmp=/&utmac=cookie value

This is a blank image that GA puts into HTML.

Thinker
But google-analytics collects a lot more data, e.g. flash version, etc. They are not send with the http headers.
echox
Yes, but it is done other way than ajax, I added explanation in post.
Thinker
Ok, i oversaw utmfl=10.0 for the flash version.Thx for the explaination.
echox
A: 

//edit: see coment at the bottom

*Ok, find an answer during a discussion with a friend of mine :-) The informations to google analytics are submitted in three ways: 1. List item 1. The HTTP Request can be analyzed with all informations of the http headers. 2. A cookie is recognized by the google analytics server. 3. An ajax call is done within the embeded javascript to submit such informations like display resolution, flash player version, etc. These informations are not transmitted via the http headers. *This is possible, because the ajax call is done in the context of the embedded javascript, so its no cross domain scripting. This was an error in reasoning by me.**

echox
Just because the file is sitting on their servers does not magically give it the power to make an XMLHttpRequest to their servers.
epascarello
You're right, tried and it didn't work.
echox