memberlogin
contactus
randomfacts

sending information in image tag with coldfusion

One of my projects was to figure out how to send reports on which products in their online catalog were being viewed the most.  I didn't want to hit their database every time a visitor was looking at a product because they had quite a few visitors.  Instead I decided to send information to a different domain using an image tag.  

First you need to embed an image tag onto the page that displays the detailed information for a specific product.  The src of the image tag will go to -- src=http://www.yourdomain.com/customerstats/thankyoucount.cfm

Now you have to create a page at  http://www.yourdomain.com/customerstats/thankyou.cfm , this page will catch the information and store it in a file or database or whatever.  In the specific coldfusion example below, I grab the  website url ( where the online catalog is located: http://www...) .  the ipaddress of the website visitor and the product number that they were viewing.  Obviously you can collect any information that you want with this.

**Setting the content type of the page to an image is important - otherwise nothing will work.  The page needs to be recognized as an image in order for the image tag


<cfparam name="url" default="">
<cfparam name="productnumber" default="">
<cfparam name="ipaddress" default="">

<cfquery name="insertrecord" datasource="#application.ds#">
 insert into catalog_tracker (websiteurl,productnumber,currentdate,ipaddress)
 values ('#websiteurl#','#productnumber#','#DateFormat(now(),"mm/dd/yyyy")# #TimeFormat(now(),"hh:mm:ss")#','#ipaddress#')
</cfquery>

<cfset thisDir = GetDirectoryFromPath(CGI.CF_TEMPLATE_PATH)>
<cfcontent type="image/gif" file="#thisDir#dot.gif">