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">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim sa As String
If Request.Url.ToString.EndsWith(".gif") Then
Response.ContentType = "image/gif"
Response.WriteFile(("~/trtr.gif"))
sa = Request.Url.ToString.Remove(0, Request.Url.ToString.LastIndexOf("/") + 1)
sa = sa.Replace(".gif", "")
Dim ads As New AccessDataSource
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
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:
History
Stay tuned for the next article which will show you how to display your data visually with pie charts and histograms.