# Migrate from Mixpanel to PostHog - Docs

> Prior to starting a historical data migration, ensure you do the following:
>
> 1.  Create a project on our [US](https://us.posthog.com/signup) or [EU](https://eu.posthog.com/signup) Cloud.
> 2.  Sign up to a paid product analytics plan on [the billing page](https://us.posthog.com/organization/billing) (historic imports are free but this unlocks the necessary features).
> 3.  Set the `historical_migration` option to `true` when capturing events in the migration. This is automated if you are running a [managed migration](/docs/migrate/managed-migrations.md).

> **✨ Use our managed migration instead:** We recently added a new managed migration for Mixpanel. It automatically exports data from Mixpanel, transforms it into PostHog's event schema, and imports it into your PostHog project. Get started with it in [managed migrations in-app](https://app.posthog.com/managed_migrations) or learn more in the [managed migrations docs](/docs/migrate/managed-migrations.md).

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](/blog/posthog-vs-mixpanel.md).

To get started, you'll need both a Mixpanel account with data and a PostHog instance. We will use [a tool](https://github.com/stablecog/mixpanel-to-posthog), built by the team at [Stablecog](https://stablecog.com/), to migrate the data and users over.

> Want us to take care of the migration for you? Our [forward-deployed engineers](/services.md) can get you up and running in super quick time.

## 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**.

Next, get the details for PostHog.

1.  Get your **project token** from the getting started flow or [your project settings](https://us.posthog.com/settings/project).
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](https://github.com/stablecog/mixpanel-to-posthog) and [clone the repo](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository).

Terminal

PostHog AI

```bash
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:

PostHog AI

```
MIXPANEL_USERNAME=posthog-migrate.a2b789.mp-service-account
MIXPANEL_PASSWORD=fCPFrpZYdzB9nlZ9kqabZcXuxSLKhjld
MIXPANEL_PROJECT_ID=2880604
POSTHOG_PROJECT_KEY=<ph_project_token>
POSTHOG_ENDPOINT=https://us.i.posthog.com
```

Next, in the terminal, make sure you have [installed Go](https://go.dev/doc/install), then run the tool in the folder location.

Terminal

PostHog AI

```bash
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
>
> PostHog AI
>
> ```bash
> 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](https://go.dev/tour/moretypes/7) 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.

### Community questions

Ask a question

### Was this page useful?

HelpfulCould be better