How to send data to Mixpanel on Mixpanel
To send data to Mixpanel, install the Mixpanel SDK in your application, initialize it with your project token, and use the track() method to send events. You can also send data via HTTP API or import historical data through the web interface.
Prerequisites
- Active Mixpanel account
- Basic understanding of JavaScript or API calls
- Access to your application's codebase
- Valid project token from Mixpanel
Step-by-Step Instructions
Get your project token
Install the Mixpanel SDK
npm install mixpanel-browser. For Node.js: npm install mixpanel. For mobile apps, add the appropriate SDK: iOS via CocoaPods pod 'Mixpanel' or Android via Gradle implementation 'com.mixpanel.android:mixpanel-android:7.+'.Initialize Mixpanel in your code
import mixpanel from 'mixpanel-browser';
mixpanel.init('YOUR_PROJECT_TOKEN'); For Node.js: const Mixpanel = require('mixpanel');
const mixpanel = Mixpanel.init('YOUR_PROJECT_TOKEN'); Replace YOUR_PROJECT_TOKEN with the token from step 1.Track your first event
mixpanel.track('Button Clicked', {
'button_name': 'Sign Up',
'page': 'Homepage',
'user_type': 'Guest'
}); The first parameter is the event name, and the second is an object with event properties.Set user properties
mixpanel.identify('user123');
mixpanel.people.set({
'$email': 'user@example.com',
'$name': 'John Doe',
'plan': 'Premium'
}); This associates events with specific users and stores user profile data.Verify data in Mixpanel dashboard
Send data via HTTP API (alternative method)
https://api.mixpanel.com/track: curl -X POST 'https://api.mixpanel.com/track' \
-d 'data=eyJldmVudCI6ICJCdXR0b24gQ2xpY2tlZCIsICJwcm9wZXJ0aWVzIjogeyJ0b2tlbiI6ICJZT1VSX1RPS0VOIn19' The data parameter must be base64-encoded JSON.Common Issues & Troubleshooting
Events not appearing in dashboard
Check that your project token is correct and that you're looking at the right project. Verify your internet connection and ensure the Mixpanel SDK is properly initialized before tracking events.
CORS errors in browser
Ensure you're using the mixpanel-browser SDK for client-side tracking, not the Node.js version. Check that your domain is whitelisted in Project Settings > CORS if you have restrictions enabled.
User properties not updating
Make sure you call mixpanel.identify() before setting people properties. Verify that you're using the correct method: mixpanel.people.set() for setting properties.
High data volume causing delays
Implement batching for high-frequency events using mixpanel.track_batch() or consider sampling non-critical events. Monitor your event volume in Project Settings > Usage.