Prior to starting a historical data migration, ensure you do the following:
- Create a project on our US or EU Cloud.
- Sign up to a paid product analytics plan on the billing page (historic imports are free but this unlocks the necessary features).
- Set the
historical_migration
option totrue
when capturing events in the migration.
PostHog is a great alternative to Mixpanel, especially if you want to replace other tools for session replay and A/B testing.
These docs walk you through pulling, formatting, and ingesting 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.
- Finally, note your API host (either
https://us.i.posthog.com
orhttps://eu.i.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.
git clone https://github.com/stablecog/mixpanel-to-posthog.git
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=posthog-migrate.a2b789.mp-service-accountMIXPANEL_PASSWORD=fCPFrpZYdzB9nlZ9kqabZcXuxSLKhjldMIXPANEL_PROJECT_ID=2880604POSTHOG_PROJECT_KEY=<ph_project_api_key>POSTHOG_ENDPOINT=https://us.i.posthog.com
Next, in the terminal, make sure you have installed Go, then run the tool in the folder location.
go run .
This triggers 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.
Importing users: The tool also includes the ability to migrate users from Mixpanel to PostHog. To do this, go to Mixpanel, select all columns, all users, get a
.csv
file, and then run the tool with the-users-csv-file
flag:Terminal
go run . -users-csv-file /path/to/users-export.csv
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 export API using the details. - Decode and format the response data from Mixpanel to one for PostHog. Although Mixpanel's schema is similar, there are many conversions needed to convert to PostHog's Schema. These include:
- Changing event names like
$mp_web_page_view
to$pageview
, - Changing event properties like
current_url_path
to$pathname
- Dropping some Mixpanel-specific properties
- Formatting the
distinct_id
depending on if it is the$device_id
or not
- Changing event names like
- 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.