The need to migrate from a product analytics platform like Mixpanel to a fully-featured platform like PostHog is a common one. In this tutorial, we'll walk through how to pull, format, and ingest data from Mixpanel into PostHog.
Curious about the similarities and differences between the two platforms? Read our comparison of PostHog vs Mixpanel.
To get started, you'll need both a Mixpanel account with data and a PostHog instance. We will use a tool, built by the team at Stablecog, to migrate the data and users over.
Gathering details
To start with, log in to Mixpanel and go to the project with the data you want to migrate.
- Create a service account. Go to "Organization Settings," click the "Service Accounts" tab, click the "Add Service Account" button, enter a name, then click "Create."
- Hold on to the username and secret for now.
- You also need your Project ID which you can get from your "Project Settings."
Next, get the details for PostHog.
- Get your project API key from the getting started flow or your project settings.
- Create a personal API key. Go to your account settings (click the photo in the top right corner, then the gear next to your email), click the "Create personal API key" button, add a name, and press save.
- Finally, note your instance address (either
https://app.posthog.com
orhttps://eu.posthog.com
or a custom domain)
With all this, we are ready to set up the migration tool.
Setting up the script
Note: The Mixpanel to PostHog migration tool is a community-built tool. Test for yourself and use at your own risk.
Go to the Mixpanel to Posthog Data Migrator repository and clone the repo. Once done, go to the newly created mixpanel-to-posthog
folder, create a .env
file, and add the details you collected.
In our example, that is:
MIXPANEL_USERNAME=ian.a2b789.mp-service-accountMIXPANEL_PASSWORD=fCPFrpZYdzB9nlZ9kqabZcXuxSLKhjldMIXPANEL_PROJECT_ID=2880604POSTHOG_PROJECT_KEY=<ph_project_api_key>POSTHOG_API_KEY=phx_lz19ZGZWrVcwZol6qLmIvHBBHzc9lQbvN8b3U2zVufZPOSTHOG_ENDPOINT=<ph_instance_address>
Next, in the terminal, make sure you have installed Go, then run the tool in the folder location.
go run .
This triggers some prompts about Mixpanel’s API URL, dates (to avoid rate limits and system crashes), and any data you missed. This should look like this:
Once successful, you can find your new data in your PostHog instance.
What the tool is doing
If you are interested in writing your own script, or just want to learn more about how Mixpanel and PostHog work, here is what the tool is doing:
- Load the details from the
.env
file and prompt for any missing details (like date range). - Make
GET
requests to the Mixpanel API using the details. - Decode and format the response data from Mixpanel to one for PostHog. For example, change
Pageview
to$pageview
and parse the properties. - Return a "slice" of formatted
MixpanelDataLine
instances. Basically, a list of formatted event objects ready to import into PostHog. - Loop through the "slice" of formatted
MixpanelDataLine
instances and use the PostHog Client (set up with the.env
details) to capture events.