Migrate from Mixpanel to PostHog

Last updated:

|Edit this page

Prior to starting a historical data migration, ensure you do the following:

  1. Create a project on our US or EU Cloud.
  2. Sign up to a paid product analytics plan on the billing page (historic imports are free but this unlocks the necessary features).
  3. Raise an in-app support request with the Data pipelines topic detailing where you are sending events from, how, the total volume, and the speed. For example, "we are migrating 30M events from a self-hosted instance to EU Cloud using the migration scripts at 10k events per minute."
  4. Wait for the OK from our team before starting the migration process to ensure that it completes successfully and is not rate limited.
  5. Set the historical_migration option to true 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.

  1. 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.
  2. Hold on to the username and secret for now.
  3. You also need your Project ID which you can get from your Project Settings.

Mixpanel

Next, get the details for PostHog.

  1. Get your project API key from the getting started flow or your project settings.
  2. Finally, note your API host (either https://us.i.posthog.com or https://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.

Terminal
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-account
MIXPANEL_PASSWORD=fCPFrpZYdzB9nlZ9kqabZcXuxSLKhjld
MIXPANEL_PROJECT_ID=2880604
POSTHOG_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.

Terminal
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:

Script

Once successful, you can find your new data in your PostHog instance.

PostHog

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:

  1. Load the details from the .env file and prompt for any missing details (like date range).
  2. Make GET requests to the Mixpanel export API using the details.
  3. 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
  4. Return a slice of formatted MixpanelDataLine instances. Basically, a list of formatted event objects ready to import into PostHog.
  5. Loop through the "slice" of formatted MixpanelDataLine instances and use the PostHog Client (set up with the .env details) to capture events.

Questions?

Was this page useful?

Next article

Migrate from Pendo to PostHog

Migrating data from Pendo is a two step process: Export data via Pendo Data Sync Convert Pendo data to the PostHog schema and capture in PostHog 1. Export data via Pendo Data Sync Pendo Data Sync enables you to export data to a warehouse like S3, Azure, or Google Cloud. This requires their highest Ultimate tier of pricing. See their docs for details on how to set it up. This exports events, features, guides, pages, and more in a .avro format which we can then convert and capture into…

Read next article