In a recent post I outlined how to use Fivetran to sync Mixpanel data to BigQuery for analysis in Looker. Today we’ll walk through how to write a SQL query to analyze a funnel using the Mixpanel data in BigQuery.
To begin, lets just look at visitors who viewed the pricing page:
You might wonder why we need the
% at the end of the URL; that’s simply to make sure the results include pages with URL parameters such as https://www.helpscout.net/pricing/?utm_source=adwords.
Next, we’ll join these results on sign up page data, making sure that the sign up page views occurred after the pricing page views:
The reason we LEFT JOIN is because not all visitors will make it to the next step of the funnel and we want the data to reflect that.
Note that we join on both the
distinct_id (to ensure each result is for a single visitor) and on the time the events occurred.
Extending this to the third and final step of the funnel, the Signed Up event, we get:
Determining the First Event Occurrence for Each Step
The query above will return every combination of pricing page views, sign up page views, and sign up events for each visitor. For our funnel though, we don’t care whether they loaded the pricing page or sign up page multiple times, we only care that they did it at all. So we modify the query to only return the first instance of each event for each visitor:
Measuring the Funnel
Finally, we count how many visitors made it to each step to get our funnel:
From here, you can take it a step further and segment the results on a property in the first step of the funnel or add a funnel duration to limit how long visitors have to complete the funnel, etc.
If you have any questions about this, don’t hesitate to reach out.