Ten Ways to Get Mixpanel Right the First Time

Arun Thampi
Jul 20, 2015 · 6 min read

Measuring what your users are doing on your site is an important part of the product building process. While almost all of us use Google Analytics as the de-facto analytics solution for our apps — it has a few limitations that some newer players address. Mixpanel is one such analytics solution that focuses on the actions that a user takes (events) as opposed to the ‘page-view’ centric approach that Google Analytics takes.

With a detailed insight into user actions, you can tailor your messaging, figure out what features are working and which ones need tweaking and, come up with a better on-boarding process for your users. Mixpanel also offers ways for you to communicate with your users (both via e-mail as well as in-app notifications) based on the actions that a user has or has not taken.

Being a Mixpanel customer for the last few years, I can say that it has been great but it can be tricky to setup the first time. Having made these Mixpanel integration mistakes at Nitrous here are the best practices that I’m applying to Nestor.

1. Use Easy-to-Grok Event Names

2. Choose a Single Place to Track Metrics

In Rails, it’s also a good practice to have all of your event tracking happen in delayed jobs outside the request cycle so that you don’t tie up your Rails action with HTTP calls to external services.

3. Use Proper Distinct IDs for Event Tracking

It is much better to use the ID of the user record in your database as the distinct ID. Database IDs have the advantage of being impervious to username/email changes.

4. Keep Track of Initial Mixpanel Data for Better Segmentation

This is how I do it in Rails with concerns and Devise:

In the registrations_controller, you then include Mixpanelable and save @mp_properties as part of the User model:

5. Track Important Events in the User Profile using the People API

6. Identify your Users Correctly

As mentioned before, Mixpanel uses Distinct IDs to track users. When a user first visits your app/site and is unauthenticated, she is allotted a random distinct ID that is cookied. The user might decide not to sign up immediately and come back at a later time to sign up. At the time of sign up, it is important that you alias the user to use the ID of the user and then start using the user’s database ID as the distinct ID for all events going forward.

In iteration#1, we weren’t doing any alias-ing at all, which meant that we weren’t able to track ‘Viewed Home Page’ -> ‘User Signed Up’ conversions.

In iteration#2, after talking to the excellent Mixpanel support crew, we started doing alias’ing but weren’t picking up the right distinct ID that Mixpanel was generating and so we were alias’ing the wrong user accounts.

It is also important to note that the *aliasing for a user must happen before any other events for that user are tracked*.

We finally got it right, and here’s a snippet demonstrating how it’s done (attributes is the mp_properties field from the previous Gist):

As always, test thoroughly during development to make sure that everything works as intended (See #10 for more).

7. Delete/De-Activate Users from Mixpanel when users cancel accounts

8. Track time instead of boolean for People API attributes

9. Use $ignore_time When Back-Filling your Mixpanel User Profiles with data

What we didn’t realize is that by calling the Mixpanel API for a given distinct ID — even if it is to use the People API to populate data for the user; Mixpanel assumes that the event was triggered by the user and thus will set the “Last Seen At” attribute of the user to the current time.

So don’t be surprised when you use the People Explorer to find out that almost your entire userbase was on your site in the last few minutes!

To avoid this, set the $ignore_time flag to true when setting attributes on User Profiles. This will ensure that the “Last Seen” attribute will not get updated and so you can back-fill as much as you please.

10. Test in Development Thoroughly

After a few painful episodes of not doing things correctly, I’ve learnt that it’s best to test and make sure your event tracking works as intended — otherwise when it’s time to make your pitch deck or present to your board, you’ll end up banging your head against the wall with numbers that don’t make any sense.

Nestor

PostScript

This is how I SaaS.

Personal endorsements and reviews of the SaaS tools we love…

Arun Thampi

Written by

Engineer at @envoy. Previously co-founded @getbotmetrics and @nitrousio. Loves building tools

This is how I SaaS.

Personal endorsements and reviews of the SaaS tools we love and use daily to get things done.

Arun Thampi

Written by

Engineer at @envoy. Previously co-founded @getbotmetrics and @nitrousio. Loves building tools

This is how I SaaS.

Personal endorsements and reviews of the SaaS tools we love and use daily to get things done.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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