“We’re switching to Mixpanel, but we don’t want to lose two years of history.”
This is one of the most common projects I take on. The history might be in another analytics tool, a data warehouse, CSV exports or application logs. Either way, you need it in Mixpanel so retention curves, cohorts and year-over-year comparisons work from day one.
The tool for the job is Mixpanel’s Import API. It’s powerful and forgiving if you prepare properly, and very unforgiving if you don’t. Imported events are effectively permanent, so a bad import means living with bad data or starting a fresh project.
This guide walks through importing historical events into Mixpanel step by step, with the validation and testing I do before touching production.
Why you can’t just use track()
Mixpanel’s /track endpoint, which the client SDKs use, only accepts events from the last 5 days. The /import endpoint is built for server-side and historical ingestion and accepts events from any time after 1 January 1971. Mixpanel’s reference compares them directly: /track uses the project token and is meant for untrusted clients; /import requires a secret or service account and is meant for servers.
Step 1: Plan the import
Before writing any code, answer these:
- What events and date range? You rarely need everything. Two years of the core events in your tracking plan is often enough.
- What will the event names and properties be? Map the old names to your new tracking plan (post 4). This is your one chance to clean up naming.
- What’s the user identifier? Historical events need a distinct ID that matches how you identify users going forward (post 2). If the history uses a different ID, map it first.
- How will you make insert IDs? Every event needs a unique, stable
$insert_idso retries don’t create duplicates. - Which project? Always a test project first.
Step 2: Create a service account
Mixpanel’s import endpoint requires an Owner or Admin service account. Create one in your organization or project settings, save the username and secret (you won’t see the secret again), and give it access to the projects you’re importing into. You’ll also need the project ID.

Treat the secret like a password. Keep it in environment variables, never in code or spreadsheets.
Step 3: Transform your data into Mixpanel’s format
Each event needs an event name and a properties object. According to Mixpanel’s Import API reference, every event must include:
event: the event nametime: when it happened, in seconds or milliseconds since epochdistinct_id: who did it$insert_id: a unique ID used for deduplication
A single event looks like this:
{
"event": "purchase_completed",
"properties": {
"time": 1704067200,
"distinct_id": "user_12345",
"$insert_id": "purchase_ORD-88421",
"order_id": "ORD-88421",
"revenue": 120.50,
"currency": "USD",
"plan": "annual"
}
}
Validation rules to check before you send
From Mixpanel’s reference:
- Each event must be under 1MB of uncompressed JSON.
- Each event must have fewer than 255 properties.
- Nested objects must have fewer than 255 keys and a maximum nesting depth of 3.
- Arrays must have fewer than 255 elements.
timecan’t be before 1971 or more than an hour in the future.
Location data
Imported events don’t come from a browser, so Mixpanel can’t geolocate them from a device. If you have location data, map it to Mixpanel’s location properties, such as city, region and country code, as shown in Mixpanel’s examples. Don’t send your own server’s IP.
Making good insert IDs
Base them on something stable in the source data, like an order ID, a source event ID, or a hash of event name + user + timestamp. Keep them short (Mixpanel’s import validation has length and character limits). Never reuse the same value for different events.
Step 4: Send batches
Mixpanel’s current reference says each request accepts up to 2,000 events and 10MB uncompressed, as JSON arrays or newline-delimited JSON. You can also gzip the body.
A Python example using requests:
import os, json, requests
PROJECT_ID = os.environ['MP_PROJECT_ID']
SA_USER = os.environ['MP_SA_USER']
SA_SECRET = os.environ['MP_SA_SECRET']
def send_batch(events):
resp = requests.post(
f'https://api.mixpanel.com/import?strict=1&project_id={PROJECT_ID}',
auth=(SA_USER, SA_SECRET),
headers={'Content-Type': 'application/json'},
data=json.dumps(events)
)
return resp.status_code, resp.json()
# Split your events into chunks of 2,000 and call send_batch for each
For EU or India residency projects, use the matching regional API host listed in Mixpanel’s reference (api-eu or api-in).
Always use strict=1
With strict=1, Mixpanel validates each batch and returns a 400 with a failed_records list explaining each event that failed, while still ingesting the valid ones. Without it, bad events can fail silently. Mixpanel recommends strict mode.
Handling errors and rate limits
- 400 errors: fix the data. Mixpanel says not to retry validation errors; they’ll fail again and still count against your rate limit.
- 429 errors: you’re sending too fast. Mixpanel recommends exponential backoff with jitter, starting around 2 seconds and doubling up to 60 seconds.
- Throughput: Mixpanel’s documented rate limit is about 2GB of uncompressed JSON per minute (roughly 30,000 events per second), and it suggests 10 to 20 concurrent clients sending 2,000-event batches for large imports.
Because every event has an $insert_id, retrying a failed batch is safe.
Using an SDK instead
Mixpanel’s server SDKs include import helpers, for example import_data in the Python library, and the mixpanel-utils module offers an import_events function. They handle batching for you, which is handy for smaller imports.
Step 5: Test before production
- Import one day of data into a test project.
- Compare event counts and unique users in Mixpanel with your source for that day. Expect small differences from timezones; Mixpanel stores events in UTC and displays them in your project timezone.
- Spot-check a few users in the Users page to confirm their history looks right.
- Build one funnel and one retention report and sanity-check them.
- Only then import the full range, into production, oldest data first.
Step 6: Connect history to live tracking
The goal is a continuous timeline. Make sure:
- Imported and live events use the same event names.
- They use the same distinct IDs for the same people.
- There’s no overlap: stop the import at the day before live tracking began, or rely on matching insert IDs if both cover the same events.
Alternatives to a custom import
- Warehouse Connectors if the history is already in BigQuery, Snowflake or similar (post 20).
- Mixpanel’s migration guides for specific tools; Mixpanel publishes guides for moving from other analytics platforms.
- Cloud ingestion from S3, Google Cloud Storage or Pub/Sub, which Mixpanel documents for larger pipelines.
Mistakes to avoid
- Importing straight into production.
- No
$insert_id, making retries create duplicates. - Old event names that don’t match your new tracking plan.
- Mismatched user IDs, so history and live data become different users.
- Retrying 400 errors.
- Timestamps in the wrong unit or timezone, which shift everything by hours or put events in 1970.
Final thoughts
A historical import is a one-time chance to start Mixpanel with clean, complete data. Map names and IDs carefully, validate with strict mode, test one day in a test project, and the history you bring over will be as trustworthy as the data you collect from now on.
Sources
- Mixpanel API reference: Import Events
- Mixpanel API reference: Track Events (track vs import)
- Mixpanel API documentation (validation, rate limits)
- Mixpanel: Event Deduplication
- Mixpanel: MCP Server, service accounts
