Skip to content

Commit

Permalink
mixpanel migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanagas committed Jul 16, 2024
1 parent e0a770a commit 3a9a996
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
2 changes: 1 addition & 1 deletion contents/docs/migrate/migrate-from-amplitude.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import MigrationWarning from "./_snippets/migration-warning.mdx"

Migrating from Amplitude is a two step process:

1. Export your data from Amplitude using the [Amplitude Export API](https://amplitude.com/docs/apis/analytics/export).
1. Export your data from Amplitude using the organizations settings export, [Amplitude Export API](https://amplitude.com/docs/apis/analytics/export), or the S3 export.

2. [Import data into PostHog](/docs/migrate) using PostHog's [Python SDK](/docs/libraries/python) or [`batch` API](/docs/api/capture) with the `historical_migration` option set to `true`. Other libraries don't support historical migrations yet.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
---
title: How to migrate from Mixpanel to PostHog
date: 2023-03-03
author:
- ian-vanagas
showTitle: true
title: Migrate from Mixpanel to PostHog
sidebar: Docs
tags:
- configuration
- events
- product os
showTitle: true
---

PostHog is a great [alternative to Mixpanel](/blog/best-mixpanel-alternatives), especially if you want to replace other tools for session replay and A/B testing.
import MigrationWarning from "./_snippets/migration-warning.mdx"

<MigrationWarning />

In this tutorial, we'll walk through how to pull, format, and ingest data from Mixpanel into PostHog.
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).
Expand All @@ -23,33 +20,37 @@ To get started, you'll need both a Mixpanel account with data and a PostHog inst

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."
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."
3. You also need your **Project ID** which you can get from your **Project Settings**.

![Mixpanel](https://res.cloudinary.com/dmukukwp6/image/upload/v1710055416/posthog.com/contents/images/tutorials/mixpanel-to-posthog/mixpanel.png)

Next, get the details for PostHog.

1. Get your **project API key** from the getting started flow or your project settings.
2. 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.
3. Finally, note your **API host** (either `https://us.i.posthog.com` or `https://eu.i.posthog.com` or a custom domain)
1. Get your **project API key** 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). Once done, go to the newly created `mixpanel-to-posthog` folder, create a `.env` file, and add the details you collected.
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).

```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:
```
MIXPANEL_USERNAME=ian.a2b789.mp-service-account
MIXPANEL_USERNAME=posthog-migrate.a2b789.mp-service-account
MIXPANEL_PASSWORD=fCPFrpZYdzB9nlZ9kqabZcXuxSLKhjld
MIXPANEL_PROJECT_ID=2880604
POSTHOG_PROJECT_KEY=<ph_project_api_key>
POSTHOG_API_KEY=phx_lz19ZGZWrVcwZol6qLmIvHBBHzc9lQbvN8b3U2zVufZ
POSTHOG_ENDPOINT=<ph_client_api_host>
```

Expand All @@ -59,26 +60,29 @@ Next, in the terminal, make sure you have [installed Go](https://go.dev/doc/inst
go run .
```

This triggers some prompts about Mixpanels API URL, dates (to avoid rate limits and system crashes), and any data you missed. This should look like this:
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](https://res.cloudinary.com/dmukukwp6/image/upload/v1710055416/posthog.com/contents/images/tutorials/mixpanel-to-posthog/script.png)

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

![PostHog](https://res.cloudinary.com/dmukukwp6/image/upload/v1710055416/posthog.com/contents/images/tutorials/mixpanel-to-posthog/posthog.png)

> **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:
> ```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 API using the details.
3. Decode and format the response data from Mixpanel to one for PostHog. For example, change `Pageview` to `$pageview` and parse the properties.
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.

## Further reading

- [What to do after installing PostHog in 5 steps](/tutorials/next-steps-after-installing)
- [Calculating average session duration, time on site, and other session-based metrics](/tutorials/session-metrics)
- [Get feedback and book user interviews with site apps](/tutorials/feedback-interviews-site-apps)
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
- Formating 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.
4 changes: 4 additions & 0 deletions src/navs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,10 @@ export const docsMenu = {
name: 'Migrate from Amplitude',
url: '/docs/migrate/migrate-from-amplitude',
},
{
name: 'Migrate from Mixpanel',
url: '/docs/migrate/mixpanel',
},
],
},
{
Expand Down
1 change: 1 addition & 0 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@
"source": "/docs/migrate/export-events",
"destination": "/docs/cdp/common-questions#why-cant-i-use-the-ui-or-events-api-to-export-data"
},
{ "source": "/tutorials/mixpanel-to-posthog", "destination": "/docs/migrate/mixpanel" },
{ "source": "/blog/categories/ceo-diaries", "destination": "/blog/ceo-diaries" },
{ "source": "/blog/categories/engineering", "destination": "/blog/engineering" },
{ "source": "/blog/categories/inside-posthog", "destination": "/blog/inside-posthog" },
Expand Down

0 comments on commit 3a9a996

Please sign in to comment.