views:

581

answers:

4

Perhaps I am missing something, but I am just learning javascript.

My understanding of Single Origin Policy is that Google Analytics should not be able to send data back to Google.

How is it able to transmit send data to Google without violating the policy?

A: 

by requesting a specific url

Andrej
How does requesting a "specific url" not violate SOP? Isn't that url on a different server (in this case Google)?
Hortitude
A: 

It is a javascript callable service provided by google..by making a request to a specific unique URI this is achieved.

Perpetualcoder
+9  A: 

From what I can tell, a webpage includes the JavaScript file from Google, then that script dynamically adds an image to the page (http://www.google-analytics.com/__utm.gif) which contains the information required for logging.

SOP does not apply to scripts, images or CSS files that are dynamically added to a page. This is why you much trust whatever JavaScript files you include in your webpages, as they will have complete control over the page.

Ryan Doherty
Where does it get the image? If it gets it from Google, doesn't this violate the policy?
Hortitude
Ryan Doherty
Got it. Very sneaky and clever.
Hortitude
I also found this information on how the image works if anyone cares:http://groups.google.com/group/analytics-help-basics/msg/815c0138973292d4
Hortitude
+1  A: 

Ryan Doherty is correct. The Google Analytics javascript code draws a transparent 1px-by-1px gif image name __utm.gif on your page. When the request (which is located on Google's servers) for this image is made, information is appended as GET parameters. Google captures this data and begins processing it. Usually within 3-6 hours, you'll see the data show up in your GA reports.

Chris