How to install the SDK on Mixpanel
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
Step-by-Step Instructions
Access your Mixpanel project settings
Choose your platform and SDK
Install the SDK package
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 mixpanelImport and initialize the SDK
JavaScript:
import mixpanel from 'mixpanel-browser';Node.js:
var Mixpanel = require('mixpanel');Then initialize with your token:
mixpanel.init('YOUR_PROJECT_TOKEN');Configure SDK settings
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.Test the installation
mixpanel.track('Test Event', { 'source': 'SDK Installation' });Check your Mixpanel dashboard under Events to confirm the test event appears within a few minutes.
Implement user identification
mixpanel.identify('user123');You can also set user properties:
mixpanel.people.set({ '$email': 'user@example.com', '$name': 'John Doe' });Verify data collection
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 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().