How to track links inside Mixpanel email notifications?

e.g. helps to check which emails have better CTRs or send additional reminders to people who click.

Sasha Eslami
Sep 24, 2017 · 6 min read

Note: I originally wrote this in 2015 and it got published in the Mixpanel blog. Then I realized this only work for “distinct ids” that are multiples of 3 digits. Since Mixpanel hasn’t created a feature for this yet, we are still using this tactic. Therefore, I thought, it can still be useful for other companies as well. So I’m republishing it:

If you’re using Mixpanel to send email notifications, then you’re probably wondering how to track which variation of the emails have more click through rates. Or you might want to send additional offers, notifications, reminders, to the people who have clicked the link inside the emails.

Mixpanel has a tracking API that makes it a little easier.

Let’s do this step by step:

1. Write JSON

Write the JSON of what event you want to be triggered to Mixpanel when the user clicks on the link, and what properties. HINT: you do NOT need to be a developer to be able to write/read a JSON.

For Example:

{“event”: “Clicked Trip Email”,

“properties”: {

“distinct_id”: “247",
“token”: “9fec45r3450b9652345db995f040f”,
“Where”: “Image”
}
}

This call means, that when Sasha, with distinct_id: 247, clicks on our link inside the email notification, an event will be sent to mixpanel with name: “Clicked Trip Email” & property name: “Where” property value “Image”. (I have two different links in the email, one of them is an image, and the other one is a link. I want to know if the user clicked on either of them, and if so, which one was clicked.)Token is mandatory which can be found inside your account settings in Mixpanel.

2. Convert to Base 64

I found this website to be pretty good at converting to Base64.

2a) Base64 of Your Distinct ID

First I try to figure out what is the Base64 equivalent to my distinct id. I’ll tell you why later.

For example, as you can see the Base64 equivalent to my distinct id (247) is MJQ3

Image for post
Image for post

2b) Base64 of the whole JSON

Now let’s find out what is the Base64 encoding of the whole JSON that you wrote in part 1.

Image for post
Image for post

2c) Find the “Right” Base64

I do a quick search (CTRL+F or Command+F) to see if I can find my Base64 equivalent of my distinct_id which is MJQ3 in the final BASE64 Encoding from the last. If yes, hallelujah! If no, try deleting couple of the “spaces” whithin the JSON and encoding it again. It should work after some tries.

3. Test it

Whatever value you get from the Base64, you insert it here:

http://api.mixpanel.com/track/?data=InsertBase64ValueHere

http://api.mixpanel.com/track/?data=eKAnGassdfDbGlja2VkIFRyaXAgRWezigJ0swqANCg0K4oCccHJvcGVydGllc+KAnTogew0KDQrigJxkaX3839pZOKAnTog4oCcMjQ3IiwNCsKg4oCcdG9r83569DQp9

If you see 1, then it has worked. If it’s a 0, then something’s wrong. Double check everything.

Image for post
Image for post

If you see a 1, you can also check in the “Live View” tab in Mixpanel to see that it shows up.

Image for post
Image for post

4. Add a Redirect

Obviously you don’t want your users to go to a page that says 1, so you want that URL to redirect them to somewhere else. So at the end of the URL I added the following

==&redirect=URLofYourWebsiteEncoded

You can’t just put http://www.geteversnap.com

You have to encode the website into a URL lingo using a website like this: http://meyerweb.com/eric/tools/dencoder/

So the encoded version of my URL is http%3A%2F%2Fwww.geteversnap.com

So all together would be

http://api.mixpanel.com/track/?data=eKAnGassdfDbGlja2VkIFRyaXAgRWezigJ0swqANCg0K4oCccHJvcGVydGllc+KAnTogew0KDQrigJxkaX3839pZOKAnTog4oCcMjQ3IiwNCsKg4oCcdG9r83569DQp9==&redirect=http%3A%2F%2Fwww.GetEversnap.com

NOTE: even if your BASE64 is wrong the redirect will still work and send the user to your website, so check your Live View to see if the event shows.

5. Replace Your Distinct ID

So that URL only sends the event based on MY distinct id. What I want to do is to be able to embed this URL in an email notification so it can send an event from ANY user.

To do that, I replace the part of the Base64 that corresponds to my distinct_id with {{${Base64 Id}}}

so it would be:

http://api.mixpanel.com/track/?data=eKAnGassdfDbGlja2VkIFRyaXAgRWezigJ0swqANCg0K4oCccHJvcGVydGllc+KAnTogew0KDQrigJxkaX3839pZOKAnTog4oCc{{${Base64 Id}}}IiwNCsKg4oCcdG9r83569DQp9==&redirect=http%3A%2F%2Fwww.GetEversnap.com

6. Embed link onto your email

Now I embed this link in any text or image inside my Mixpanel Email Notification.

Image for post
Image for post

7. Create Base64 ID People Property

Before you turn on the email notification, you need to add a people property to each user, which includes the Base64 encoding of the users’ distinct_id. Property name: {{${Base64 Id}}} & property value.

Every programming language has it’s own internal function that can convert a string to Base64, just consult with your backend developer.

e.g. for python: https://docs.python.org/2/library/base64.html

8. Results

Now I can go to the analytic of my notifications, and see out of all the different variants of a certain notification which one has had more clicks:

Image for post
Image for post

I can also see out of the people who clicked in this email, what percentage clicked where.

Image for post
Image for post

Questions? Just add a note next to the paragraph or sentence you have questions about and I’ll respond.

Hope this helps.

BONUS: Auto Email/Push Notification to People who Clicked

Now what if you could automatically send the users who clicked a push or email notification later on?

To do so, you want a people property automatically added to the users’ Mixpanel properties when they click on the link.

In the following JSON I am setting a people property “Clicked Upgrade Plan” as true

{
“$distinct_id”: “247",
“$token”: “9fec459d0f”,
“$set”: {
“Clicked Upgrade Plan”: “true”
}
}

Convert it Base64:

Ww0KeyasdfuY3RfaW2364355wNCiAgICAgICAgIasdflbiI6ICI5ZmVjNDU5ZDasdfTFjNWRiOTRjMWRiOTVWdub3Jsadf3RpbWUiO

Add Mixpanels “Engage” API before it.

http://api.mixpanel.com/engage/?data=Ww0KeyasdfuY3RfaW2364355wNCiAgICAgICAgIasdflbiI6ICI5ZmVjNDU5ZDasdfTFjNWRiOTRjMWRiOTVWdub3Jsadf3RpbWUiO

Add your redirect at the end:

http://api.mixpanel.com/engage/?data=Ww0KeyasdfuY3RfaW2364355wNCiAgICAgICAgIasdflbiI6ICI5ZmVjNDU5ZDasdfTFjNWRiOTRjMWRiOTVWdub3Jsadf3RpbWUiO =&redirect=http%3A%2F%2Fwww.GetEversnap.com

URL encode the above link:

http%3A%2F%2Fapi.mixpanel.com%2Fengage%2F%3Fdata%3DWw0KeyasdfuY3RfaW2364355wNCiAgICAgICAgIasdflbiI6ICI5ZmVjNDU5ZDasdfTFjNWRiOTRjMWRiOTVWdub3Jsadf3RpbWUiO%20%3D%26redirect%3Dhttp%253A%252F%252Fwww.GetEversnap.com

Add the above argument instead of the redirect website you had at the end of the previous event tracking link from part 4.

http://api.mixpanel.com/track/?data=eKAnGassdfDbGlja2VkIFRyaXAgRWezigJ0swqANCg0K4oCccHJvcGVydGllc+KAnTogew0KDQrigJxkaX3839pZOKAnTog4oCc{{${Base64 Id}}}IiwNCsKg4oCcdG9r83569DQp9==&redirect=http%3A%2F%2Fapi.mixpanel.com%2Fengage%2F%3Fdata%3DWw0KeyasdfuY3RfaW2364355wNCiAgICAgICAgIasdflbiI6ICI5ZmVjNDU5ZDasdfTFjNWRiOTRjMWRiOTVWdub3Jsadf3RpbWUiO%20%3D%26redirect%3Dhttp%253A%252F%252Fwww.GetEversnap.com

Replace your Base64 distinct_id from above link with {{${Base64 Id}}}:

http://api.mixpanel.com/track/?data=eKAnGassdfDbGlja2VkIFRyaXAgRWezigJ0swqANCg0K4oCccHJvcGVydGllc+KAnTogew0KDQrigJxkaX3839pZOKAnTog4oCc{{${Base64 Id}}}IiwNCsKg4oCcdG9r83569DQp9==&redirect=http%3A%2F%2Fapi.mixpanel.com%2Fengage%2F%3Fdata%3DWw0KeyasdfuY3RfaW2364355wNCiAgICAgICAgIasdflbiI6ICI5ZmVjNDU5{{${Base64 Id}}}jNWRiOTRjMWRiOTVWdub3Jsadf3RpbWUiO%20%3D%26redirect%3Dhttp%253A%252F%252Fwww.GetEversnap.com

Congratulations! This gigantic link first sends an event to Mixpanel about the click and then adds a people property and then redirects to your website.

Now you can go create an email or push notification and target only the people whose “Clicked Upgrade Plan” is Set.

Wanna help?

Why don’t you create a web app that can just get the main variables and spit out the link at the end? I even made a mock up for you☺. Let me know.

Product Management Tips & Tricks

Here are some tips and tricks from the people who have…

Sasha Eslami

Written by

Product Manager, Startup Founder, Music producer, Zouk/Bachata Dancer, & mental-health junkie

Product Management Tips & Tricks

Here are some tips and tricks from the people who have worked really hard to discover them. You will not find these tips anywhere else on Internet,

Sasha Eslami

Written by

Product Manager, Startup Founder, Music producer, Zouk/Bachata Dancer, & mental-health junkie

Product Management Tips & Tricks

Here are some tips and tricks from the people who have worked really hard to discover them. You will not find these tips anywhere else on Internet,

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store