How to detect if a link was clicked through an email in gmail

Viewed 2657

I am working on an email that will be sent out as a marketing effort. Within the email there will be a button that will allow people to "save the date" of the event and I want to be able to detect if the email was opened in gmail after the button is clicked, and if it was opened in gmail it would serve a Google Add to Calendar link - else it would serve an ICS file.

There is another email that does exactly this, it does not detect user agent since, regardless of the browser and os and device, if the email was opened in gmail it would redirect to google's add to calendar!

I've been trying to figure this out for a while now and have tried many trick, though none successful, I would love to see what other ideas people have.

Edit: I noticed that gmail will add data-saferedirecturl to all links

I'm wondering if there is a way to detect this?

2 Answers

If you to know the source of the click on your link, you can do so by using a trick with images:

  1. Inside your mail, insert a tiny image pointing to your domain (Preferably with a different identifier for every recipient.
  2. When user first opens your mail, the Gmail proxy server will send your server a request to get the picture.
  3. You can identify the request coming from the Gmail proxy server using any of the indicative elements of the request (Like IP address, User-Agent and such).

Though, note that: If the recipient opens the mail again in Gmail, you won't see a request to your server, since this picture is saved in the proxy server's cache.

Related