Click here to Skip to main content
12,455,701 members (67,922 online)
Click here to Skip to main content
Add your own
alternative version

Stats

26.1K views
229 downloads
25 bookmarked
Posted

Using 404 Not Found For An Email Tracking Image / Webbug

, 12 Nov 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
The technique of inserting email tracking images, which avoids the give away querystring

Introduction

This code offers a very simple way to track emails and see whether or not they have been displayed by the recipient. Because this technique does not put a query string after an image, it is undetectable by spam engines, making it appropriate for legitimate newsletters, etc. that you want to track without being spam blocked.

Background

Tracking emails by logging the request for an image is a commonly used technique. This example varies from many in that it does not need a query string after the image to send back information about the user, e.g.

someimage.gif?userdata=12345 which is easily spotted by antispam engines.

Instead this method stores the user data in the name of the image, i.e.

myLogoUser12345.gif which is indistinguishable from any other image request.

In order to use this technique, we must re-configure IIS to call our page instead of the standard 404 page not found. Whenever a request comes for a gif- image that does not exist, we log that request and return a logo or in this case, a transparent 8x8 pixel GIF.

Using the Code

Simply put the following code in a page called 404.aspx, set up your access database (or change for SQL if you have a SQL Server at your disposal) and you can start tracking.

To track an email, simply include a remote image in your message. The remote image in the email points to an image on your server. The trick is that the image MUST NOT ACTUALLY EXIST. This causes our custom 404 handler to be called. Our custom handler then returns a transparent 8x8 pixel GIF, and the request is logged in a database.

<%@ Page Language="VB" %>

<script runat="server">

' this page is configured in IIS to replace the standard 404 page not found page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 
Dim sa As String 

' at this point we already know the page / file does not exist, now we check to see
' if a gif was requested 
If Request.Url.ToString.EndsWith(".gif") Then 

' first we return the invisible 8x8 gif trtr.gig 
Response.ContentType = "image/gif" 
Response.WriteFile(("~/trtr.gif")) 

'next we log the request in our database, the name of the gif forms our tracking data 
sa = Request.Url.ToString.Remove(0, Request.Url.ToString.LastIndexOf("/") + 1) 
sa = sa.Replace(".gif", "") 
Dim ads As New AccessDataSource 

' replace this with the location of your writeable database 
ads.DataFile = "D:\websites\thear1\data\campaign.mdb" 
ads.InsertCommand = "INSERT INTO [tracking] ([keyword], [time], [date], [url],
    [referer]) VALUES (?, ?, ?, ?, ?)" 
ads.InsertParameters.Add("keyword", Request.ServerVariables("REMOTE_ADDR")) 
ads.InsertParameters.Add("time", Now.ToLongTimeString) 
ads.InsertParameters.Add("date", Now.Date) 
ads.InsertParameters.Add("keyword", sa) 
ads.InsertParameters.Add("referer", Request.ServerVariables("REMOTE_ADDR")) 
ads.Insert() Else 

' the missing file / page was not a gif, so return as page not found message 
sa = Request.Url.ToString.Remove(0,
    Request.Url.ToString.LastIndexOf("/") + 1) Response.Write("Page " &
    sa & " does not exist ") 

End If 

End Sub 

&</script>

Changing IIS to Use Your Page for 404 Requests

If you do not have access to your own server, then you will need to ask your hosting company to point your 404 page not found page to your custom 404.aspx page (which most companies will do without issue).

Launch inetmgr then go to the custom errors tab and modify the 404 entry:

changing IIS

History

Stay tuned for the next article which will show you how to display your data visually with pie charts and histograms.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jon Anthony
Chief Technology Officer
United Kingdom United Kingdom

You may also be interested in...

Comments and Discussions

 
GeneralUsing Captcha to stop spam Pin
Jon Anthony20-Nov-09 10:31
memberJon Anthony20-Nov-09 10:31 
GeneralRe: Using Captcha to stop spam Pin
Keith Yerian16-Dec-11 2:36
memberKeith Yerian16-Dec-11 2:36 
GeneralAnother approach. Pin
gstolarov19-Nov-09 4:39
membergstolarov19-Nov-09 4:39 
GeneralRe: Another approach. Pin
Jon Anthony20-Nov-09 10:11
memberJon Anthony20-Nov-09 10:11 
GeneralI agree with another poster. It appears to me that you are encouraging spam Pin
Shane Story17-Nov-09 2:50
memberShane Story17-Nov-09 2:50 
GeneralRe: I agree with another poster. It appears to me that you are encouraging spam Pin
Chris Maunder17-Nov-09 11:48
adminChris Maunder17-Nov-09 11:48 
GeneralRe: I agree with another poster. It appears to me that you are encouraging spam Pin
Shane Story17-Nov-09 13:22
memberShane Story17-Nov-09 13:22 
GeneralRe: I agree with another poster. It appears to me that you are encouraging spam Pin
WPKF17-Nov-09 20:29
memberWPKF17-Nov-09 20:29 
GeneralRe: I agree with another poster. It appears to me that you are encouraging spam Pin
Shane Story18-Nov-09 2:49
memberShane Story18-Nov-09 2:49 
GeneralRe: I agree with another poster. It appears to me that you are encouraging spam Pin
Chris Maunder22-Nov-09 12:54
adminChris Maunder22-Nov-09 12:54 
GeneralHow to stop spam with CAPTCHA challenge Pin
Jon Anthony20-Nov-09 10:30
memberJon Anthony20-Nov-09 10:30 
General404 - DOS attack Pin
ComplexityChaos16-Nov-09 2:53
memberComplexityChaos16-Nov-09 2:53 
GeneralRe: 404 - DOS attack Pin
Jon Anthony20-Nov-09 10:12
memberJon Anthony20-Nov-09 10:12 
GeneralASP.NET Routing Pin
HightechRider13-Nov-09 6:22
memberHightechRider13-Nov-09 6:22 
GeneralRe: ASP.NET Routing Pin
Jon Anthony14-Nov-09 1:54
memberJon Anthony14-Nov-09 1:54 
GeneralExample Database has information in the wrong fields Pin
Dewayne Dodd13-Nov-09 5:37
memberDewayne Dodd13-Nov-09 5:37 
GeneralRe: Example Database has information in the wrong fields [modified] Pin
Jon Anthony14-Nov-09 1:51
memberJon Anthony14-Nov-09 1:51 
RantIf you have to out-think spam filters, YOU'RE SPAM! Pin
dwilliss12-Nov-09 15:20
memberdwilliss12-Nov-09 15:20 
GeneralRe: If you have to out-think spam filters, YOU'RE SPAM! Pin
vmarcano13-Nov-09 0:04
groupvmarcano13-Nov-09 0:04 
I almost agree. The larger companies have reputation control down to a fine art, smaller businesses do not have the resource to send from reputation controlled ip addresses run by bulk email providers.
For smaller companies that want to track open rates the problems exists.

Personally I would be in favour of challenge response techniques to cut out spam all together. i.e. if you send me a mail and my server does not know you, it sends a challenge email with a CAPTCHA image. Of course only humans can accurately reply to CAPTCHA, at which point you could be whitelisted. Its a project I would like to get around to working on at some point. I think the bigger vendors would not pursue this, as the concept threatens all companies that send automated newsletter / spam / etc


Questionimage must not exist Pin
vmarcano12-Nov-09 14:03
groupvmarcano12-Nov-09 14:03 
AnswerRe: image must not exist Pin
Jon Anthony12-Nov-09 14:06
memberJon Anthony12-Nov-09 14:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160826.1 | Last Updated 12 Nov 2009
Article Copyright 2009 by Jon Anthony
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid