How to add back dated events in mixpanel?
Hi Tripatjot S., Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> 👋
Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai
To add backdated (historical) events in Mixpanel, you cannot use the standard client-side or server-side SDKs' .track() methods, as these only accept events with timestamps within the last 5 days. Events older than 5 days will not be ingested via the /track API endpoint.To import events older than 5 days, you must use the /import API endpoint. This endpoint is designed for bulk and historical data ingestion. Mixpanel provides several ways to do this:
1. Use Mixpanel SDKs with Import Support
- Python SDK: Use the .import_data() function.
- Ruby SDK: Use the import() function.
- Go SDK: Use the Import() function.**Example using Python SDK:from mixpanel import Mixpanelmp = Mixpanel("YOUR_PROJECT_TOKEN") mp.import_data( "YOUR_API_SECRET", [ { 'event': 'Backdated Event', 'properties': { 'distinct_id': '12345', 'time': 1609459200, # Unix timestamp for the backdated event # ... other properties ... } } ] )Example using Ruby SDK:require 'mixpanel-ruby' tracker = Mixpanel::Tracker.new("YOUR_PROJECT_TOKEN") tracker.import("API_KEY", "12345", "Backdated Event", { 'time' => 1609459200, # ... other properties ... })Example using Go SDK:**LBKSevent := mp.NewEvent("import test event", mixpanel.EmptyDistinctID, nil) event.AddTime(time.Now().AddDate(0, 0, -10)) // 10 days ago event.AddInsertID("insert_id") importEvents := []*mixpanel.Event{event} mp.Import(ctx, importEvents, mixpanel.ImportOptionsRecommend)LBKSMixpanel SDKs: Python, Mixpanel SDKs: Ruby, Mixpanel SDKs: Go
2. Use Mixpanel Warehouse Connector
If your historical data is stored in a data warehouse, you can use the Mixpanel Warehouse Connector to import both events and user data directly into Mixpanel.
3. Use Mixpanel Utils
For migrations or bulk imports, you can use the mixpanel-utils open source library, which provides helper functions for exporting and importing events.
Important Notes
- Always include a unique $insert_id property for each event to prevent duplication.
- Ensure your event data is properly formatted and compatible with your Mixpanel project settings.
- For large backfills, consider importing a limited subset first to validate your process before a full import.
- The /import API supports importing events up to 5 years in the past, but some pipeline tools may have a 6-month limit for backfills, so check the documentation for your specific method.For more details, see the official Mixpanel documentation on backfilling historical data and importing historical events.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
kapa.ai can you share more details on /import endpoint
Let me check the knowledge base for you again. One moment! 📚
Certainly! Here are more details on the /import endpoint in Mixpanel: ---
Purpose
The /import endpoint is used to send batches of events—including historical (backdated) events—from your servers to Mixpanel. It is designed for server-side integrations and supports importing events that occurred at any time after 1971-01-01, unlike the /track endpoint, which only accepts events from the last 5 days Import Events.---
Request Format
- Batch Size: Up to 2000 events and 10MB uncompressed per request.
- Content-Type: Supports application/json (array of events) or application/x-ndjson (newline-delimited JSON objects).
- Compression: Supports Content-Encoding: gzip to reduce network egress.
- Authentication: Requires a service account (project_id, username, password) or can use a project token as the basic auth username with an empty password.**Example JSON (application/json)::**LBKS```LBKS[
{
"event":: "Signup",
"properties": {
"time": 1618716477000,
"distinct_id": "91304156-cafc-4673-a237-623d1129c801",
"$insert_id": "29fc2962-6d9c-455d-95ad-95b84f09b9e4",
"Referred by": "Friend",
"URL": "mixpanel.com/signup"
}
},
{
"event": "Purchase",
"properties": {
"time": 1618716477000,
"distinct_id": "91304156-cafc-4673-a237-623d1129c801",
"$insert_id": "935d87b1-00cd-41b7-be34-b9d98dd08b42",
"Item": "Coffee",
"Amount": 5.0
}
}
]LBKS**Example NDJSON (application/x-ndjson):**LBKS{"event": "Signup", "properties": {"time": 1618716477000, "distinct_id": "91304156-cafc-4673-a237-623d1129c801", "$insert_id": "29fc2962-6d9c-455d-95ad-95b84f09b9e4", "Referred by": "Friend", "URL": "mixpanel.com/signup"}}
{"event": "Purchase", "properties": {"time": 1618716477000, "distinct_id": "91304156-cafc-4673-a237-623d1129c801", "$insert_id": "935d87b1-00cd-41b7-be34-b9d98dd08b42", "Item": "Coffee", "Amount": 5.0}}```Import Events---
Required Fields
Each event object must include:
- event: The event name (string).
- properties: An object containing:
- time: The event timestamp (seconds or milliseconds since epoch).
- distinct_id: The unique identifier for the user.
- $insert_id: A unique identifier for the event (for deduplication).---
Authentication
- Service Account: Use project_id, service account username, and password. - Project Token: Can be used as the basic auth username with an empty password if project_id is not specified Import Events.---
Parameters
- strict (query parameter): When set to 1 (recommended), Mixpanel will validate the batch and return errors per event that failed.
- project_id (query parameter): The Mixpanel project_id, required for service account authentication.---
Limits
- Events per request: 2000 - Request size: 10MB uncompressed - Event size: Each event must be smaller than 1MB of uncompressed JSON and have fewer than 255 properties. - Rate limits: 2GB of uncompressed JSON per minute or ~30k events per second (rolling 1 minute basis). For higher limits, contact Mixpanel support Track Events.---
Example cURL Request
--url '[https://api.mixpanel.com/import?strict=1&project_id=<YOUR_PROJECT_ID](https://api.mixpanel.com/import?strict=1&project_id=<YOUR_PROJECT_ID) >' \
--header 'Content-Encoding: gzip' \
--header 'Content-Type: application/json' \
--header 'accept: application/json' \
--header 'authorization: Basic <BASE64_ENCODED_AUTH> ' \
--data-binary @your_events.json.gzLBKS```LBKS[Import Events](https://docs.mixpanel.com/docs/migration/amplitude#import-api)LBKS---LBKSFor more details, see the [official Mixpanel Import Events documentation](https://github.com/mixpanel/docs/blob/main/reference/Ingestion%20API/events/import-events.md).
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
kapa.ai I sent the event does it take time to reflect on mixpanel?
Let me check the knowledge base for you again. One moment! 📚
Yes, there can be a short delay before events you send appear in Mixpanel. The Mixpanel SDKs are designed to batch events and send them to the server every 60 seconds while your application is running, and also when the application transitions to the background. You can manually force a flush to send events immediately if needed. However, after ingestion, there may still be a brief processing time before the events are visible in the Mixpanel UI and reports Mixpanel SDKs: Android, Mixpanel SDKs: React Native, Mixpanel SDKs: Unity.If you are importing historical or backdated events, there may be additional processing time before these events are fully available in your reports. You can check the $import property and mp_processing_time_ms to confirm when data has been ingested Debugging: Delayed Ingestion.In summary, while events are usually available quickly, some delay is normal due to batching, network, and processing times.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
kapa.ai Also how to set country
Let me check the knowledge base for you again. One moment! 📚
To set the country for an event or a user profile in Mixpanel, you can manually specify the country property in your payload. For events, use the property mp_country_code; for user profiles, use $country_code. These properties should be set to the 2-letter country code (e.g., "US" for United States).**Example for an event::**LBKS```LBKS{
"event":: "Signed Up",
"properties": {
"distinct_id": "13793",
"token": "project_token",
"mp_country_code": "US",
"$city": "San Francisco",
"$region": "California"
}
}LBKSLBKS**Example for a user profile:**LBKS{
"$token": "project_token",
"$distinct_id": "13793",
"$set": {
"$country_code": "US",
"$region": "California",
"$city": "San Francisco"
}
}```When you manually define these geolocation properties, Mixpanel will use your provided values instead of deriving them from the IP address. This is especially useful for server-side tracking or when you have more accurate location data than what IP-based geolocation provides Manual Geolocation Tracking.If you do not set these properties manually, Mixpanel will attempt to infer them from the IP address of the request Default Properties: Automatically collected properties.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
kapa.ai can we update existing mixpanel events?
Let me check the knowledge base for you again. One moment! 📚
In general, Mixpanel events are immutable once ingested—you cannot directly edit or update existing event data after it has been received by Mixpanel. This is a core part of Mixpanel’s data model and is explicitly stated in the documentation: > "You cannot directly edit the raw event data that has already been ingested into your Mixpanel project; events are immutable once received (unless imported via a mirror sync warehouse connector)." FAQ: Sending Data to MixpanelHowever, there is an exception if you are using the Warehouse Connector in Mirror mode. With Mirror mode, Mixpanel can keep events in sync with your data warehouse, including updates and deletes. This allows you to update or delete events in your warehouse and have those changes reflected in Mixpanel. These update and delete operations are counted as billable events when using Mirror mode Warehouse Connectors: Billing FAQ.Summary: - Standard Mixpanel events cannot be updated after ingestion. - You can update events if you use the Warehouse Connector in Mirror mode, which syncs changes from your data warehouse to Mixpanel.If you need to correct or enrich historical event data and are not using Mirror mode, the recommended approach is to delete the problematic data and re-import the corrected events Data Clean-Up.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
kapa.ai can we delete a event via api based on some flag in metadata?
