Click here to Skip to main content
Click here to Skip to main content

Using 404 Not Found For An Email Tracking Image / Webbug

, 12 Nov 2009
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)

About the Author

Jon Anthony
Chief Technology Officer
United Kingdom United Kingdom
the world is yours
drupal development
Android & iPhone development
Follow on   Twitter

Comments and Discussions

 
GeneralHow to stop spam with CAPTCHA challenge PinmemberJon Anthony20-Nov-09 10:30 
General404 - DOS attack PinmemberComplexityChaos16-Nov-09 2:53 
GeneralRe: 404 - DOS attack PinmemberJon Anthony20-Nov-09 10:12 
GeneralASP.NET Routing PinmemberHightechRider13-Nov-09 6:22 
GeneralRe: ASP.NET Routing PinmemberJon Anthony14-Nov-09 1:54 
GeneralExample Database has information in the wrong fields PinmemberDewayne Dodd13-Nov-09 5:37 
GeneralRe: Example Database has information in the wrong fields [modified] PinmemberJon Anthony14-Nov-09 1:51 
RantIf you have to out-think spam filters, YOU'RE SPAM! Pinmemberdwilliss12-Nov-09 15:20 
GeneralRe: If you have to out-think spam filters, YOU'RE SPAM! Pingroupvmarcano13-Nov-09 0:04 
Questionimage must not exist Pingroupvmarcano12-Nov-09 14:03 
AnswerRe: image must not exist PinmemberJon Anthony12-Nov-09 14:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web03 | 2.8.140718.1 | Last Updated 12 Nov 2009
Article Copyright 2009 by Jon Anthony
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid