How to record url variables (query string) from an

2019-08-31 03:33发布

问题:

I want to do something similar to what Google Analytics does to track visitor information. Google Analytics' javascript file puts a 1x1 img on your site. When a visitor comes to your site, they load that IMG from Google. The IMG SRC attribute includes a number of URL variables about your visit. For example:

<img src="http://www.google-analytics.com/__utm.gif?utmwv=5.4.6&utms=1&utmn=116154048&utmhn=www.example.com&utmcs=UTF-8&utmsr=1920x1080&utmvp=1439x356...">

When Google receives the request for this image, they record the URL variables.

I can create an image with a custom source with all the URL variables I need. That's easy. But I can't think of how to record it on the server? I want it to end up in a database so I can run reports. My server is running IIS7 and ColdFusion 10. Any ideas?

Thanks!

回答1:

Back in the days before ajax, people used to create a .cfm page that served up a small transparent gif via cfcontent.

 <cfcontent type="image/gif" file="c:/path/to/clear.gif">

Since the script actually returns a valid image, it can be used as the src of an <img> tag.

 <img src="path/to/yourScript.cfm?param1=xxx&param2=yyyy" />

When the image is displayed, the URL variables are passed to the .cfm script, and you can easily insert the values into a database. Just be sure you always return an image, even if a database error occurred for some reason.

I am sure there are slicker options, but that is the basic concept of how it could be achieved using only an <img> tag.