最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What exactly does this url mean? - Stack Overflow

programmeradmin1浏览0评论

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 : .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 ?

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./__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 ?

Share Improve this question edited Feb 24, 2009 at 8:00 ConroyP 42k16 gold badges82 silver badges86 bronze badges asked Feb 24, 2009 at 6:46 ShobanShoban 23k8 gold badges66 silver badges107 bronze badges
Add a ment  | 

7 Answers 7

Reset to default 4

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

Have done this in asp 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 monly 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.

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.

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.

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. 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.

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 mon way of sending data back for analytics purposes.

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

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']);
发布评论

评论列表(0)

  1. 暂无评论