How can I track the links included inside my Mixpanel email messages?

Mixpanel allows you to easily track open rates of email messages with one click. But because there is no way to execute JavaScript within an email, tracking click-through rates of links sent within an Mixpanel email message is a bit tricker (albeit possible!).

If the link in your Mixpanel email points to your own site or domain

In this case, the recommended method is to track an Event on the page rather than tracking the click activity itself from within the email.

For example, let’s say the link in your email goes to the signup page on your site:

http://mydomain.com/signup

Append a custom query string param to this link, for example:

http://mydomain.com/signup?emailclick=campaign123

And if this query string param is present in the link, then send an Event, for example:

if(window.location.href.indexOf("emailclick") > -1){
     mixpanel.track("Email link clicked", {
          "Link name": window.location.href.split("emailclick=")[1]
     });
}

If the link in your Mixpanel email does not point to your own site or domain

In this case, use Mixpanel’s HTTP spec to fire an Event, and use the redirect parameter to send the user to the desired URL. Your request will look something like this:

http://api.mixpanel.com/track/?data=eyJldmVudCI6ICJnYW1lIiwgInByb3BlcnRpZXMiOiB7ImlwIjogIjEyMy4xMjMuMTIzLjEyMyIsICJkaXN0aW5jdF9pZCI6ICIxMjM0IiwgInRva2VuIjogInRva2VuIiwgInRpbWUiOiAxMjQ1NjEzODg1LCAiYWN0aW9uIjogInBsYXkifX0===&redirect=http://YOUREXTERNALPAGE.COM

Replace the link in your email with this request; when clicked, the Event will fire and the user will be redirected to the destination URL.

Note: There is no way to place distinct_id in the track call above to tie clicks back to specific users, as you'd need to generate a unique link for every email. So if the link is to an external page, you will not be able to use this Event within Funnels or Retention. You will be able to use Segmentation to see how many times users in general clicked a particular link.