Migrate to PostHog from Amplitude

Last updated:

|Edit this page

If you're running close to Amplitude's 10 million free events limit, migrating to PostHog could be a good idea, especially since the PostHog event schema is quite similar to Amplitude's.

Steps

  1. Export your data from Amplitude using the Amplitude Export API
  2. Import data into PostHog using any of PostHog's SDKs or capture API.

Translating the data schema

Roughly, for every Amplitude event, you'll need to:

  • Capture the event: this involves calling the Capture events with the event name, timestamp, event properties, and user properties
  • Alias the user: if this is a logged-in user, you'll want to Alias the device ID to the user

Capture the event

For reference, as of writing, Amplitude's event structure is (according to their Export API documentation:

{
"event_time": UTC ISO-8601 formatted timestamp,
"event_name": string,
"device_id": string,
"user_id": string | null,
"event_properties": dict,
"group_properties": dict,
"user_properties": dict,
// A bunch of other fields that include things like
// device_carrier, city, etc.
...other_fields
}

When capturing the event, roughly, the schema you'll want to use is:

JavaScript
const distinctId = user_id || device_id;
const eventMessage = {
properties: {
...event_properties,
...other_fields,
$set: { ...user_properties, ...group_properties },
$geoip_disable: true,
},
event: event_type,
distinct_id: distinctId,
timestamp: event_time,
};

In short:

  • We want to track the event with the same:
    • Event name
    • Timestamp
  • For the distinct ID, we either want to use the User ID if present, or the Device ID (a UUID string) if not
  • We want to track both User and Group properties as User Properties using properties: {$set}
  • We want to track Event properties using properties

Aliasing device IDs to user IDs

In addition to tracking the events themselves, we want to tie users' events both before and after login. For Amplitude, events before and after login look a bit like this:

EventUser IDDevice ID
Application installednull551dc114-7604-430c-a42f-cf81a3059d2b
Login123551dc114-7604-430c-a42f-cf81a3059d2b
Purchase123551dc114-7604-430c-a42f-cf81a3059d2b

We'd ideally like to be able to attribute "Application installed" to the user with ID 123, so we need to also call alias with:

JavaScript
const aliasMessage = {
distinct_id: user_id, // 123
aliasId: device_id, // 551dc114-7604-430c-a42f-cf81a3059d2b
};

Since you only need to do this once per event, ideally you'd store somewhere (e.g., in a SQL table outside of PostHog) a record of which aliases you'd already sent to PostHog, so that you don't end up sending the same Alias events twice.

Questions?

Was this page useful?

Next article

How to migrate to EU Cloud

Warning: Migrating event data to PostHog's EU Cloud is a time-consuming process, likely to take several days or weeks. We strongly recommend users with a large amount of event data begin by setting up and connecting a new EU cloud instance and migrating data later, if needed. For many companies, teams, and products, keeping customer data within the EU is critical for compliance with regulations such as GDPR. To help them with this, we’ve created an EU Cloud hosting option. It includes all the…

Read next article