This post helps you with loading your data from Mixpanel to PostgreSQL. If you are looking to get analytics-ready data without the manual hassle, you can integrate Mixpanel to PostgreSQL with RudderStack, so you can focus on what matters, getting value out of your business data.
Extract data from Mixpanel
Mixpanel is an analytics-as-a-service application, so naturally, it requires data to offer its analytics features. We usually think of it as a consumer of data and not a place where we would get our data in order to do perform analysis. But Mixpanel collects a lot of data related to how your customers use your product, and in the case where you would like to do anything that also involves data from others sources, you really have two choices.
The first one is to enrich the data of Mixpanel with data coming from other sources and the second one is to extract the data Mixpanel holds for you and load it on a data warehousing repository for further analysis. This post will consider the second case.
Mixpanel is evolving into a platform where apart from the analytics services that it offers, you will also be able to build applications that are integrated with it. In this post, we will work only with the Export API which purpose is to allow us to export our data from Mixpanel.
As a web API, you can access it using by using tools like CURL or Postman or your favorite http client for the language or framework of your choice. Some options are the following:
- Apache HttpClient for Java
- Spray-client for Scala
- Hyper for Rust
- Ruby rest-client
- Python http-client
Or you can use the libraries/SDKs that Mixpanel offers for the following languages:
As a RESTful API, it offers the following resources that you can interact with:
- annotations– list the annotations for a specified date range.
- create– create an annotation
- update– update an annotation
- delete– delete an annotation
- export– get a “raw dump” of tracked events over a time period
- events– get total, unique, or average data for a set of events over a time period
- top– get the top events from the last day
- names– get the top event names for a time period
- properties– get total, unique, or average data from a single event property
- top– get the top properties for an event
- values– get the top values for a single event property
- funnels– get data for a set of funnels over a time period
- list– get a list of the names of all the funnels
- segmentation– get data for an event, segmented and filtered by properties over a time period
- numeric– get numeric data, divided up into buckets for an event segmented and filtered by properties in a time period
- sum– get the sum of a segment’s values per time unit
- average– get the average of a segment’s values per time unit
- Segmentation Expressions– a detailed overview of what a segmentation expression consists of
- retention– get data about how often people are coming back (cohort analysis)
- addiction– get data about how frequently people are performing events
- engage– get People Analytics’ data
Let’s assume that we want to export our raw data from Mixpanel. To do so we’ll need to execute requests to the export endpoint. An example of a request that would get us back raw events from Mixapanel looks like this:
https://data.mixpanel.com/api/2.0/export/?from_date=2012-02-14&expire=1329760783&sig=bbe4be1e144d6d6376ef5484745aac45 &to_date=2012-02-14&api_key=f0aa346688cee071cd85d857285a3464& where=properties%5B%22%24os%22%5D+%3D%3D+%22Linux%22&event=%5B%22Viewed+report%22%5D
The returned result is always in JSON serialization with one event per line sorted by increasing timestamp. It looks like the following sample: