Track user events and behaviors
curl --request POST \
--url https://api.mixpanel.com/import \
--header 'Content-Type: application/json' \
--data '
{
"event": "<string>",
"properties": {
"token": "<string>",
"distinct_id": "<string>",
"time": 123,
"$insert_id": "<string>"
}
}
'{
"code": 123,
"num_records_imported": 123,
"status": "<string>",
"failed_records": [
{
"index": 123,
"insert_id": "<string>",
"field": "<string>",
"message": "<string>"
}
]
}Documentation Index
Fetch the complete documentation index at: https://mintlify.com/mixpanel/docs/llms.txt
Use this file to discover all available pages before exploring further.
1 (recommended), Mixpanel validates the batch and returns errors per event that failed.Options: 0 or 1application/json: Standard JSON arrayapplication/x-ndjson: Newline-delimited JSONgzipShow properties
curl https://api.mixpanel.com/import?strict=1&project_id=YOUR_PROJECT_ID \
-u SERVICE_ACCOUNT_USERNAME:SERVICE_ACCOUNT_SECRET \
-H "Content-Type: application/json" \
-d '[
{
"event": "Signed Up",
"properties": {
"time": 1609459200,
"distinct_id": "user123",
"$insert_id": "28a0f0a8-4e8c-4c4e-b8c1-832e9e5c5e5e",
"signup_method": "email",
"plan": "premium"
}
},
{
"event": "Purchase",
"properties": {
"time": 1609459260,
"distinct_id": "user123",
"$insert_id": "3f9a2c5b-7d1e-4b2a-9c3d-4e5f6a7b8c9d",
"amount": 29.99,
"currency": "USD",
"item_name": "Premium Plan"
}
}
]'
{
"code": 200,
"num_records_imported": 2,
"status": "OK"
}
1, uses the IP address of the request to determine geolocation1, returns a verbose JSON response instead of simple 1 or 0curl https://api.mixpanel.com/track \
--data-urlencode data='[
{
"event": "Page View",
"properties": {
"token": "YOUR_PROJECT_TOKEN",
"distinct_id": "user123",
"time": 1609459200,
"page_name": "Homepage",
"referrer": "google.com"
}
}
]'
1 for success, 0 for failure.
Always use $insert_id for deduplication
import uuid
properties = {
"$insert_id": str(uuid.uuid4()),
"distinct_id": "user123",
"time": int(time.time())
}
Use server-side tracking when possible
Batch events for better performance
batch = []
for i in range(2000):
batch.append(create_event(...))
response = requests.post(url, json=batch)
Use meaningful event names
Include relevant context in properties
{
"event": "Purchase Completed",
"properties": {
"amount": 29.99,
"currency": "USD",
"item_name": "Premium Plan",
"payment_method": "credit_card",
"coupon_code": "SAVE10"
}
}
Invalid timestamp
'properties.time' is invalid: must be specified as seconds since epochSolution: Ensure timestamps are in seconds (not milliseconds) or milliseconds (with 13 digits)# Correct: seconds
"time": int(time.time())
# Correct: milliseconds
"time": int(time.time() * 1000)
Missing required fields
event nameproperties.distinct_idproperties.timeproperties.$insert_id (for /import)Payload too large
request exceeds max limit of 2097152 bytesSolution:curl --request POST \
--url https://api.mixpanel.com/import \
--header 'Content-Type: application/json' \
--data '
{
"event": "<string>",
"properties": {
"token": "<string>",
"distinct_id": "<string>",
"time": 123,
"$insert_id": "<string>"
}
}
'{
"code": 123,
"num_records_imported": 123,
"status": "<string>",
"failed_records": [
{
"index": 123,
"insert_id": "<string>",
"field": "<string>",
"message": "<string>"
}
]
}