Finding out whether or not the gift card email you sent has been read by your recipients is a great way to gather insight about your email.

It can also indicate (although see important caveats below) whether or not your emails are reaching users’ inboxes or are getting caught in a spam filter, as very few people open emails in their spam folder.

At Giftbit, email deliverability of gifts is core to our business, and open tracking is one of many statistics we collect and analyze to improve our product. It is also a metric we make available to our customers as part of their gift card orders.

New call-to-action

How to do it

Email open tracking is a simple concept and implementation:

  1. Create a standard webapp driven URL in your product that accepts your tracking information via the URL or in parameters, but always return an image content type and corresponding binary image data (such as ‘image/gif’, and usually a 1×1 pixel transparent .gif).
  2. Embed the URL as the src of a tag in all outgoing emails you wish to track, adding appropriate information to the URL to identify the email and information you wish to track. Because the returned content type is an image, it will render properly as an image.
  3. Done! Whenever an email is opened and that tiny invisible image is rendered, your URL will be called. Capture and store the information to your database, etc.

Learn how to automate your reward program in just a few clicks.

Working example

All code samples are written in Groovy/Grails, but can easily be applied to any web framework / language.

Step 1 - create your controller

Your controller has two jobs:

Accept tracking information and do something with it. This example shows an image tracking controller that accepts a URL that looks like an image (http://yoursite.com/opens/somestat/TrackingInformation123.gif), rather than a standard dynamic page (http://yoursite.com/opens/somestat?track=TrackingInformation123). The reason for doing it this way is to avoid it being identified as a web bug and stripped out by email clients and email scanning programs.

Return the actual binary data of the image and set the appropriate content type of the response.

New call-to-action

In this example, we are tracking opens of gift emails. To track additional emails, you could try adding additional methods (which in grails are exposed as URL paths). This avoids a long single controller method with conditionals for different tracking types.

class OpenController {
     def openTrackingService

     def giftinstance() {
     String giftcode = params.id?.replaceAll('.gif', '')
     if (giftcode) {
          openTrackingService.trackGiftInstanceEmailOpen(giftcode)
     }
     sendTrackingImageToResponse()
     }

     //add additional tracking as needed.
     //def someOtherEmail() {}

     public void sendTrackingImageToResponse() {
     response.contentType = 'image/gif'
     response.outputStream << openTrackingService.get1pixelTrackingImageAsBytes()
     response.outputStream.flush()
     }

Here is the source for the service. While very simple, resist the urge to put your database interaction into your controller. Good encapsulation is fundamental to code health and maintainability.

New call-to-action

Of note is the definition of the 1×1 pixel image data. Given that it is such a tiny amount of data, simply store the byte array from a 1×1 pixel transparent gif for performance and simplicity, rather than go and actually load the image data from a file/URL/Classpath every time it is needed.

class OpenTrackingService {
   private final byte[] singlePixelTransparentShimBytes = [71, 73, 70, 56, 57, 97, 1, 0, 1, 0, -128, 0, 0, -1, -1, -1, 0, 0, 0, 33, -7, 4, 1, 0, 0, 0, 0, 44, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 2, 68, 1, 0, 59]

     public byte[] get1pixelTrackingImageAsBytes() {
     return singlePixelTransparentShimBytes
     }

     public void trackGiftInstanceEmailOpen(String giftCode) {
     //update your tracking database/datastore accordingly.
     GiftInstance giftInstance = giftCode ? GiftInstance.findByGiftcode(giftCode) : null;
     if (giftInstance) {
          giftInstance.lastOpened = new Date()
          giftInstance.save()
      }
     }

     //public void trackSomeOtheStuff(def data) {}
}

Step 2 - add your image tag to your emails

For any email you want to track, simply add an tag to call your controller as part of the email source. Usually this is done as part of the footer.

<img src="http://yoursite.com/open/giftinstance/GIFTCODE123.gif" alt="">

This would result in the giftcode ‘GIFTCODE123′ being tracked every time the email is opened.

New call-to-action

Important caveats

  • Your email must be sent as HTML (not plaintext), even if it is otherwise text, otherwise the tag will not function.
  • In order for open tracking to work, the recipient must render images in their email reader. If your email is text heavy, it is possible it may be opened and read without the user ever choosing to ‘display images.’ This solution works best with media rich email, in which your recipient will almost definitely choose to display images if they wish to read it.
  • Many email readers cache images, so while you can rely on your URL being called for the first open, it should not be relied on to be called every subsequent time the person reads or displays the email.
  • If you use a third party mail provider / mailing list tool, it is likely they have something similar to this already built in. Don’t roll your own if you can use something you already have available to you.

New call-to-action

A quick word on click throughs

If your email is actionable, click throughs (the act of a user following a link from the email) are a great statistic to measure rather than, or in addition to, opens.

They work with plaintext emails and are easy to measure by adding a parameter to your destination in the links in the email (http://yoursite.com/destination?fromemail=emailidentifier) or handling all your email links through a central tracking controller that does statistics recording and then sends the user to the real destination (http://yoursite.com/fromemail?emailid=something&destination=).

The advantage of the latter approach is that you don’t need your tracking business logic scattered throughout your application if there are many destinations.

Learn more about Giftbit.

Click throughs are often considered a ‘better’ metric because they show actual engagement and aren’t skewed by potential technical or user behaviour limitations that prevent images in emails from being rendered.

New call-to-action