How to track funnels with Mixpanel

Funnel Analysis allows you to increase conversions for any goal you have in mind by quickly identifying problem areas in your application's flow. For a more in-depth explanation about what funnel analysis is and why it's useful please check out our blog post: Introduction to analytics - Funnel Analysis

Basic API function explanation


mpmetrics.track_funnel(funnel, step, goal, properties, callback)

The description of these are as follows:

  • funnel is the name of the funnel you wish to track, it can be anything.
  • step is position in the funnel, you must start at 1 and can go up to 255. Mixpanel expects consecutive steps, users will not be counted if they go from step 1 to 3 in step 3. Our service will check to make sure the user was seen in previous steps before counting them and only counts unique visitors.
  • goal is the name of what you're tracking at a certain step. Goals must stay the same per step. We do not track multiple goals for a single step at this time.
  • properties are an object map (or dictionary) that are exactly like properties in normal event tracking. Properties will let you segment users between funnel steps.

For the funnel to function, you must include a distinct_id or an ip with the request. If you are making an AJAX request, we will pull the ip from there.

Please note, user data is rejected for Step n if the user was not seen in Step n-1 (previous step) where n > 1 (i.e. skipping steps is not allowed). Visitors may repeat steps however they will only be counted once.

You are expected to include our Javascript library just like normal event tracking. A Facebook one is available as well.

Real example


If you haven't done so already, include the Javascript library on your page:

<script type="text/javascript" src="http://api.mixpanel.com/site_media/js/api/mixpanel.js"></script>
<script type="text/javascript">
try { var mpmetrics = new MixpanelLib("YOUR_TOKEN"); } catch(err) {}
</script>

Then, you can begin logging funnel data: 

    Step 1: mpmetrics.track_funnel("Ticket Purchasing", 1, "Impression");
    Step 2: mpmetrics.track_funnel("Ticket Purchasing", 2, "Lead");
        

In step 1, we are tracking when the user lands on the first page of our ticket selling website, so we count the impression. In step 2, we are tracking when the user buys a ticket. You simply include each line in the relevant part of your code - step 1 on page load, and step 2 when they add their information via a form. Your funnel can easily span your entire website, as each step is fired by the relevant event.

Advanced example with properties


Properties really differentiate our funnel analysis tool from the rest because they allow you to segment users between steps. Imagine you knew the gender of your users and wanted to track how gender affects a user from step 1 to step 2 of your funnel, we can do this.

Example

Step 1: mpmetrics.track_funnel("Ticket Purchasing", 1, "Impression", {"gender" : "male"});
Step 2: mpmetrics.track_funnel("Ticket Purchasing", 2, "Lead", {"gender" : "male"});

Just like event tracking you're welcome to use as many as you want and are allowed to track whatever you want. You can easily extend this to tracking the performance of an ad-campaign and the like. Our service will automatically do the analysis in real-time.

Tracking multiple funnels with ease and events


If you find tracking multiple funnels tedious and would like to simply use events as your funnels steps we have a solution for that.

mpmetrics.register_funnel(funnel_name, steps) is an easy way to do this. For example:

mpmetrics.register_funnel("View Video", ["Impression", "Search", "Rate Video", "View Video"]);
mpmetrics.register_funnel("View Video 2", ["Impression", "Search", "View Video", "Rate Video"]);

You can pre-define your funnels ahead of time and provide a list of events which is the sequence of your funnel. You'll notice the last two steps are different and "Rate Video" is step 4 instead of step 3 in the second funnel.

A requirement is that you're tracking those 4 events in your application but you will only need to define them once when the action occurs. Our library will take care of the rest in terms of funnel tracking which means you can define your funnels in one area.

Example screenshot of our funnel