Skip to main content

Data Ingestion Best Practices

This guide covers best practices for implementing scalable, maintainable tracking in Mixpanel. Follow these guidelines to ensure high-quality data and avoid common pitfalls.

Create a Tracking Plan

A tracking plan is a centralized document that defines what data you’re collecting and why. It should:
  • Define your business goals and KPIs
  • Outline events, event properties, and user profile properties
  • Serve as the source of truth for your implementation
  • Be continuously updated as your product evolves
  • Be shared across product, marketing, and engineering teams

Tracking Plan Template

Download our tracking plan template to get started

Tracking Plan Methodology

1

Define KPIs

Start with your top KPIs and metrics that measure success. Don’t try to track everything - prioritize what matters most.
2

Map User Flows

Map each KPI to the user actions that influence it. Consider different paths users take to achieve outcomes.
3

Translate to Events

Break down user flows into specific events and properties. Each event should represent a meaningful user action.
4

Iterate

Start with your most critical data and iterate. Tracking everything leads to wasted effort and unused data.

Industry-Specific Templates

Mixpanel provides tracking plan templates for different industries:

Server-Side Best Practices

Server-side tracking is more reliable than client-side tracking. Follow these practices to get the most value:

Track Browser, Device, and OS

Mixpanel’s web and mobile SDKs automatically parse the User-Agent header. For server-side tracking, you need to do this manually:

Track UTM Parameters and Referrer

Capture marketing attribution data by parsing URL parameters and headers:

Track Page Views Consistently

For server-side implementations:
  • Use a single event name for all page views (e.g., “Page Viewed”)
  • Track page name as a property, not as different events
  • Fire page view events only on successful responses
  • Handle both anonymous and identified users
  • Parse headers and URL for analytics properties

Handle Geolocation

By default, Mixpanel uses the IP address of the request. For server-side tracking:
Read our full guide on managing geolocation.

Identity Management

Server-Side Identity Management

Server-side SDKs don’t generate IDs automatically. You’re responsible for:
  • Generating unique IDs for users
  • Maintaining ID persistence across requests
  • Linking anonymous users to identified users
Read our Server-side ID Management guide.

Best Practices for IDs

  • Choose a format and stick with it (e.g., database IDs, UUIDs)
  • Never change a user’s distinct_id after it’s set
  • Use the same ID across all platforms (web, mobile, server)
For anonymous users:
  • Generate a unique device_id on first visit
  • Store it in a cookie or local storage
  • Use it as distinct_id until user identifies
  • Call $identify to merge when user signs up
When a user signs up or logs in:
Only merge once per user to avoid data issues.

Event Design Best Practices

Naming Conventions

Use Object + Action format: “Video Played”, “Purchase Completed”, “Profile Updated”This makes events easier to read and organize.
Good Examples:
  • “Video Played”
  • “Purchase Completed”
  • “Page Viewed”
  • “Form Submitted”
Bad Examples:
  • “play_video” (inconsistent format)
  • “user clicked the signup button” (too verbose)
  • “event_123” (meaningless)

Property Best Practices

  • Choose a naming convention (snake_case or camelCase) and stick with it
  • Use the same property name across all events when referring to the same thing
  • Document your naming conventions in your tracking plan
  • Strings: Names, categories, IDs
  • Numbers: Counts, prices, durations
  • Booleans: Yes/no flags
  • Dates: ISO 8601 format or Unix timestamps
Use consistent values to make filtering and segmentation easier:
Don’t send personally identifiable information:
  • ❌ Full names, addresses, phone numbers
  • ❌ Credit card numbers, SSNs
  • ❌ Passwords or tokens
  • ✅ User IDs, anonymized identifiers
  • ✅ Email (if properly hashed)

Debugging Your Implementation

Create a Test Project

Always create a separate development project to validate your implementation without contaminating production data.

Use Events View

The Events view shows a live feed of incoming events:
  1. Fire test events from your own device
  2. Search by your distinct_id or device_id
  3. Expand events to inspect all properties
  4. Verify event and property names are correct
  5. Check that property values have correct data types
Events Filter

Enable Debug Mode

Most client-side SDKs support debug mode:

Check Browser Console (Web)

For web implementations:
  1. Enable debug mode
  2. Open browser developer console
  3. Go to Network > Fetch/XHR tab
  4. Perform actions that trigger events
  5. Look for requests to Mixpanel API:
    • US: api.mixpanel.com/track
    • EU: api-eu.mixpanel.com/track
    • India: api-in.mixpanel.com/track
  6. Verify the token and payload are correct

Common Issues

Possible causes:
  • Wrong project token
  • Wrong API endpoint for data residency
  • Events older than 5 days sent to /track (use /import instead)
  • Ad-blockers (for client-side tracking)
  • Events are hidden in Lexicon
Solutions:
  • Verify project token in Project Settings
  • Check that you’re using the correct API endpoint
  • For old events, use the /import endpoint
  • Check Lexicon for hidden events
Cause: Server-side tracking uses the server’s IP by defaultSolution: Pass the client’s IP:
Cause: Events sent multiple times or from multiple sourcesSolution: Use $insert_id to deduplicate:
Cause: Mobile SDKs batch events and flush periodicallySolution:
  • iOS: Flushes every 60 seconds or when app backgrounds
  • Android: Flushes every 60 seconds or after 40 events
  • Call flush() manually for important events

Performance & Reliability

Use Batching

Batch multiple events in a single request:

Implement Retry Logic

Queue Events

For high-volume applications, queue events and send asynchronously:

Security Best Practices

Never expose API secrets in client-side codeYour project token is safe to use in client-side code, but your API secret should only be used server-side.
  • ✅ Use project token in web/mobile apps
  • ✅ Use API secret only on servers
  • ❌ Don’t commit API secrets to version control
  • ❌ Don’t send sensitive data (PII, passwords, etc.)

Data Quality Checklist

Before launching:
  • Created a tracking plan
  • Tested in a development project
  • Verified events appear in Events view
  • Checked event and property names follow conventions
  • Confirmed property data types are correct
  • Tested identity merge for signup/login flows
  • Verified geolocation is accurate
  • Set up separate dev/staging/production projects
  • Documented implementation for team
  • No PII or sensitive data in events

Next Steps

ID Management

Learn advanced identity management strategies

Debugging Guide

Detailed debugging and troubleshooting guide