Reputation: 1035
I am current using PHP to output a 1x1 pixel that I include in e-mails. Before I output the image, I run a couple of scripts (i.e. increment a view count etc...). However, I've noticed that clients like GMail & Outlook download the image before serving it to the user and, of course, this counts as a view, because the image is being viewed. I send the e-mail and before even opening it I get a response in my server that the tracking pixel has been viewed and then when I open the e-mail, I get a second response.
My question is, within the tracking pixel, how can I truly tell when the user has opened the e-mail and not when a client like GMail or Outlook is just downloading the image?
Upvotes: 1
Views: 4389
Reputation: 31
You can look at the headers from the request made to your server.
When email clients download images to cache for future use/opens the header is not the same as when the user opens the email.
For example, when Gmail server requests your image, you will see the headers 'referer: http://mail.google.com
' and 'accept: image/webp,*/*;q=0.8
;
This is not the case when the user opens the email (the user-agent will change as well, but does not actually show the end user's
Note: Google can always change the way they handle their image proxy protocol along with the headers sent. Keep in mind that it may change in the future.
Upvotes: 3
Reputation: 895
What I would do is check the amount of times Gmail, Outlook, etc. opens requests pixel without showing it to the user and substract it from the total times the pixel was viewed. If the total times the pixel was views is greater than 0, then the user opened it.
For example: A test email sent to your Gmail account tells you that the pixel was requested by Gmail 2 times and you haven't opened the email yet.
2 total requests - 2 Gmail server requests = 0 (email not viewed)
User then opens email 1 time... 3 total requests - 2 Gmail server requests = 1 (email was viewed once)
User opens the email 5 times... 7 total requests - 2 Gmail server requests = 5 (email was viewed five times)
Hope this was useful!
Upvotes: -1