views:

1243

answers:

7

I am using different analytics tags in one of our web applications. Most of them call a javascript code for tracking.

Some tags have url of gif image with querystrings.

Example : http://www.google-analytics.com/__utm.gif?utmwv=45.542

What exactly does this url do? How do they get the values from querystring?

Update: (After reading some answers) I know every browser will load the gif which is 1x1 pixel. But how are they getting the values from query string? in the above case how can they retrieve the value of utmwv? Any code samples ?

A: 

The query string is still sent to the server when you request an image.

Of course, I don't know the exact details of how they are working with the data on the server, but a .gif is a fairly common way of sending data back for analytics purposes.

Andy Hume
+1  A: 

Just like you can pass query strings to ASP.NET pages, you can actually pass query strings to any URL; if you use a MVC-based framework like ASP.NET MVC or Rails, capturing the parameters from a URL like this is easy. Then, all you have to do is return a GIF image.

Paul Betts
A: 

well .. __utm.gif is a 1x1 pixel image which google must be logging access to - which means they are collecting the query string value in their logs also. nothing tricky about that really. i thot utmwv was a version number, but not clear what that number means

Scott Evernden
how mate? I know its gif and any browser will load it. But how are they getting the value from the query string. Any code? :) Thanks for the reply
Shoban
+1  A: 

Any browser will load an image at his url, even without javascript. When it does, the query string parameters and the request headers from the client can be captured for analytics. So it allows analytics to be captured without javascript at all.

Squeegy
How can it be captured? was my question :)
Shoban
The host that this url connects to is a web application. This web application can interact with their own database and inspect the query string and header as much as it likes. After its done doing all that, the web application returns a small gif as the response to the request.
Squeegy
+4  A: 

Basically, you write a script in your preferred language, and map that script to yourtrackingscript.gif. ..jpg, png even.

Have done this in asp.net using a http handler.

The script reads the querystring like any other dynamic page (aspnet, asp, php, anything really), then writes it to a db or log file, or does whatever else you want to do with it.

Then set the content-type header appropriately e.g "image/gif", and send back a 1 pixel image, or any other sized image you like.

For just a 1 pixel image, I have opened up a 1 pixel spacer.gif type image in a hex editor, and hard coded it as a byte array to send out as the response, will save a little IO overhead if it gets hit a lot, alernatively, you can read a file from disk or DB and send that back instead.

This is a commonly used trick in email newsletters to track open rates etc.
Often the hardest bit about it is when you don't have enough rights to map the url to the script on a shared machine, but you can develop it as a normal script/program, then get the mapping sorted out once you have it working.

Most modern browsers will respond to a an aspx or php (.etc...) url as an image if it sends the right headers, it's older browsers, browser nanny plugins, and email clients that are the most pernickety about it.

seanb
+1  A: 

That's no GIF, that's a space station (beta)!

In other words, although the URL seems to point to an image, the webserver at www.google-analytics.com hands this request to some processing script, which then extracts the data and sends a 1x1 GIF image content back to the browser.

Here's an example using the Apache webserver and mod_rewrite:

# in .htaccess
RewriteEngine On
RewriteRule ^__utm\.gif /someprocessingscript.php [QSA]

<?php // in someprocessingscript.php
do_some_tracking($_GET); // this would probably analyze and log data
header('Content-Type: image/gif');
readfile('1x1.gif');
exit;
?>

Another option: serve a real GIF (probably with Cache-Control: no-cache), log all accesses, analyze logs afterwards. This may be faster, as this requires no internal rewriting and no scripting on every access.

Piskvor
A: 

But how are they getting the values from query string? in the above case how can they retrieve the value of utmwv? Any code samples ?

If they want the calling page they have the referer, if they want their parameters they have the request URI.

print($_SERVER['HTTP_REFERER']);
print($_SERVER['REQUEST_URI']);
VirtualBlackFox