One of the most common problems of working with email communication between the companies and its clients is that there isn’t a way of proving that user has received the email without making him click on a link to the company site thus confirming the read.
As most webmail and mail applications can read HTML emails (and most companies sends HTML emails anyway), we can take advantage of this to help transparently track the view.
A web beacon is a image that is requested via a crafted address that triggers a call to register the view and then displays to the browser or mail client the requested gif image with its headers. Usually it’s used a 1px per 1px transparent GIF.
To this we’ll need Apache’s mod_rewrite and PHP only. Recording the data depends on you: Save on a file or into the database.
Apache’s mod_rewrite
This will morph our undercover-spy-GIF URL into the parsing script URL so the client will not know he is actually being watched.
I use a pattern to make the URL look like a normal image so I’ve made this all into the company logo image URL:
http://www.companydomain.com/img/vouchers/wb/RESERVATIONCODE/BEACONTYPE/logo-top.gif
NOTE: As you can imagine, when the system sent the emails he stamps each one with their respectively crafted logo-top.gif image URL with the RESERVATIONCODE and BEACONTYPE.
RESERVATIONCODE and BEACONTYPE were short numbers and a little encoded to obsfucate.
Here’s the deal:
RewriteRule ^img/voucher/wb/([0-9]+)/([1-2])/logo-top.gif$ /triggerWebbeacon.php?reservation_id=$1&btype=$2 [L]
There are 2 regular expressions here: The first allows numeric values (RESERVATIONCODE) and the second allows values of 1 and 2 (my constants for Beacon Type).
NOTE: There were in this case 2 beacon types because the same voucher were sent to the client and to the supplier so we tracked both.
The PHP short-example
NOTE: This is a short-example so no input validation will be present on it.
<?php $res_id = $_GET['reservation_id']; $btype = $_GET['btype']; $timestamp = date("Y-m-d H:i:s"); // Get current timestamp // Note: You can use your preferred date functions as mktime, time etc // Record the data switch ($btype): case 2: $field = 'wb_supplier'; break; case 1: default: $field = 'wb_client'; endswitch; $res = mysql_query("UPDATE reservations SET '{$field}' = '{$timestamp}'"); ?>
NOTE: This is a non-reliable way of tracking email views since nowadays most mail applications and webmail services blocks external images by default. I’ve put my beacon on the company logo so users that don’t wan’t to see ugly email are seduced to click ‘show images’.
There are much to explore on that as you create more complex tracking systems.
SIDENOTE: The Web Beacon is a.k.a. Web Bug
Very nice, although as you said, this is most ineffective nowadays, because remote images are blocked due to privacy concerns in most clients.
A small correction: the rewrite rule is missing the “$1″, it’s just “$” as you posted, and won’t work as it is.
Bruno Lustosa
January 24, 2009 at 8:37 pm
Oops, mistyped!
Thanks Bruno!
Jan Seidl
January 24, 2009 at 10:34 pm
Finally someone who can write a good blog ! . This is the kind of information that is useful to those want to increase their SERP’s.
I loved your post and will be telling others about it. Subscribing to your RSS feed now. Thanks
PHP Tutorials
April 25, 2009 at 4:01 pm
Hi, its a so nice and good site ever. Its a really great and fantastic post here in this site, i appreciate that. Thank you for the sharing of your ideas and thoughts to all of us.
scripts
December 30, 2009 at 9:07 am
How exactly do i use these codes? I’m not a programmer but I do have a web site. What code do I use when inserting the image in a mail/ What do i put in my server?
Guest
January 31, 2010 at 11:54 pm
You’ll probably need a programmer to code that for you, you’ll need a basic email sending infrastructure since image must be generated according to the email address and you’ll need a back end to verify the readings tough.
Jan Seidl
February 2, 2010 at 9:30 am
i love it
LeeThong
September 27, 2011 at 2:58 pm