Beginner
How to install the SDK on Mixpanel
Quick Answer
Installing the Mixpanel SDK involves selecting your platform, adding the SDK to your project dependencies, and initializing it with your project token. The process varies slightly depending on whether you're using JavaScript, iOS, Android, or server-side languages.
Prerequisites
- Active Mixpanel account
- Project token from Mixpanel dashboard
- Development environment set up
- Basic knowledge of your chosen programming language
1
Access your Mixpanel project settings
Log into your Mixpanel account and navigate to Settings in the left sidebar. Click on Project Settings and locate your Project Token. Copy this token as you'll need it for SDK initialization.
Tip
Keep your project token secure and never expose it in client-side code for server-side implementations.
2
Choose your platform and SDK
Go to Implementation in your Mixpanel dashboard or visit the Mixpanel developers documentation. Select your platform from the available options: JavaScript, iOS, Android, Python, Node.js, or other supported languages.
3
Install the SDK package
For JavaScript:
For Node.js:
For iOS: Add
For Android: Add
For Python:
npm install mixpanel-browserFor Node.js:
npm install mixpanelFor iOS: Add
pod 'Mixpanel' to your PodfileFor Android: Add
implementation 'com.mixpanel.android:mixpanel-android:7.+' to your build.gradle fileFor Python:
pip install mixpanelTip
Always use the latest stable version of the SDK for the best performance and security updates.
4
Import and initialize the SDK
Add the import statement to your code:
JavaScript:
Node.js:
Then initialize with your token:
JavaScript:
import mixpanel from 'mixpanel-browser';Node.js:
var Mixpanel = require('mixpanel');Then initialize with your token:
mixpanel.init('YOUR_PROJECT_TOKEN');5
Configure SDK settings
Set up additional configuration options during initialization. For JavaScript:
mixpanel.init('YOUR_PROJECT_TOKEN', {
debug: true,
track_pageview: true,
persistence: 'localStorage'
});Adjust settings like debug mode, automatic pageview tracking, and data persistence based on your needs.Tip
Enable debug mode during development to see tracking events in your browser console.
6
Test the installation
Send a test event to verify the installation:
Check your Mixpanel dashboard under Events to confirm the test event appears within a few minutes.
mixpanel.track('Test Event', { 'source': 'SDK Installation' });Check your Mixpanel dashboard under Events to confirm the test event appears within a few minutes.
7
Implement user identification
Set up user identification for better tracking:
You can also set user properties:
mixpanel.identify('user123');You can also set user properties:
mixpanel.people.set({ '$email': 'user@example.com', '$name': 'John Doe' });Tip
Always identify users with a consistent unique identifier across sessions for accurate user analytics.
8
Verify data collection
Navigate to your Mixpanel dashboard and go to Events to see incoming data. Check the Live View to monitor real-time events. Ensure your events are properly categorized and user profiles are being created under Users.
Tip
Data may take up to 5-10 minutes to appear in your dashboard after being sent.
Troubleshooting
Events not appearing in dashboard
Check that your project token is correct and that you're looking at the right project. Verify network connectivity and ensure events are being sent by checking browser developer tools or server logs.
SDK initialization errors
Ensure you've installed the correct SDK version for your platform. Check that all dependencies are properly installed and that you're using the correct import syntax for your environment.
CORS errors in browser
Add your domain to the Allowed Domains list in your Mixpanel project settings under Access Security. For development, you may need to add
localhost and your local development URLs.User identification not working
Make sure you're calling
mixpanel.identify() before setting user properties. Verify that the user ID is a string and consistent across sessions. Check that you're using mixpanel.people.set() for user properties, not mixpanel.track().Ready to get started with Mixpanel?
Put this tutorial into practice. Visit Mixpanel and follow the steps above.
Visit Mixpanel →