SDKs overview
Mixpanel offers Software Development Kits (SDKs) and client libraries designed to facilitate the integration of its product analytics platform into various applications. These SDKs enable developers to track user interactions, manage user profiles, and send data to Mixpanel for analysis. The available SDKs cover a range of platforms, including web, mobile, and server-side environments, providing methods for identifying users, tracking events, and setting user properties, which are fundamental to understanding user behavior and product engagement Mixpanel JavaScript Quickstart.
The SDKs are generally structured to abstract the underlying API calls, allowing developers to focus on defining relevant events and properties rather than managing HTTP requests directly. This approach aims to streamline the implementation process and reduce potential errors during data collection. Mixpanel also provides detailed documentation and quickstart guides for each SDK, outlining installation procedures, basic usage patterns, and advanced configuration options Mixpanel SDK reference documentation.
Beyond official offerings, community-contributed libraries and integrations exist, extending Mixpanel's reach to additional programming languages or specific frameworks. These community efforts, while not officially maintained by Mixpanel, can offer solutions for niche use cases or alternative integration methods Mixpanel API client libraries blog post.
Official SDKs by language
Mixpanel maintains official SDKs for primary development environments. These SDKs are regularly updated and supported, providing robust integration points for event tracking and user analytics. The following table details the core official SDKs:
| Language/Platform | Package/Module | Installation Command (Example) | Maturity |
|---|---|---|---|
| JavaScript (Web) | mixpanel-browser |
npm install mixpanel-browser or via CDN |
Stable |
| Python | mixpanel |
pip install mixpanel |
Stable |
| Ruby | mixpanel-ruby |
gem install mixpanel-ruby |
Stable |
| Java | mixpanel-java |
Maven/Gradle dependency | Stable |
| PHP | mixpanel/mixpanel-php |
composer require mixpanel/mixpanel-php |
Stable |
| iOS (Swift/Objective-C) | Mixpanel-swift |
CocoaPods, Swift Package Manager, or Carthage | Stable |
| Android (Kotlin/Java) | mixpanel-android |
Gradle dependency | Stable |
| Unity | Unity Package | Import via Unity Package Manager | Stable |
| React Native | mixpanel-react-native |
npm install mixpanel-react-native |
Stable |
| Flutter | mixpanel_flutter |
flutter pub add mixpanel_flutter |
Stable |
| Electron | mixpanel-browser |
npm install mixpanel-browser |
Stable (uses JS SDK) |
Each SDK provides specific methods for initializing the client, identifying users, tracking events, and managing user properties. Developers can refer to the Mixpanel developer documentation for comprehensive guides on each platform.
Installation
Installation methods for Mixpanel's SDKs vary by programming language and environment. The general process involves adding the SDK as a dependency to your project and then initializing it with your Mixpanel project token. Below are common installation patterns for several key SDKs:
JavaScript (Web)
For web applications, the JavaScript SDK can be installed via npm or included directly using a Content Delivery Network (CDN).
# Via npm
npm install mixpanel-browser
# Via CDN (in your HTML <head> tag)
<script type="text/javascript">
(function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(e,f,c){function g(a,d){var b=d.split(".");2==b.length&&(a=a[b[0]],d=b[1]);a[d]=function(){a.push([d].concat(Array.prototype.slice.call(arguments,0)))}};e=f;c=c||{};c.api_host=c.api_host||"https://api.mixpanel.com";b._i.push([e,f,c]);return b}
;g(b,"track");g(b,"identify");g(b,"set_group");g(b,"track_pageview");g(b,"register_once");g(b,"unregister");g(b,"register");g(b,"alias");g(b,"push");g(b,"disable");g(b,"enable");g(b,"reset");g(b,"group");g(b,"time_event");g(b,"get_group");g(b,"start_session");g(b,"end_session");g(b,"opt_in_tracking");g(b,"opt_out_tracking");g(b,"has_opted_in_tracking");g(b,"has_opted_out_tracking");g(b,"clear_opt_in_out_tracking");
b.people=b.init("",f,c).people;g(b.people,"set");g(b.people,"set_once");g(b.people,"unset");g(b.people,"increment");g(b.people,"append");g(b.people,"union");g(b.people,"track_charge");g(b.people,"clear_charges");g(b.people,"delete_user");
var a=document.createElement("script");a.type="text/javascript";a.async=!0;a.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";
var m=document.getElementsByTagName("script")[0];m.parentNode.insertBefore(a,m)
})(document,window.mixpanel||[]);
mixpanel.init('YOUR_PROJECT_TOKEN', {
debug: true,
track_pageview: true,
persistence: 'localStorage'
});
</script>
Python
Python developers can install the SDK using pip, the standard package installer for Python.
pip install mixpanel
iOS (Swift)
For iOS development, Mixpanel-swift can be installed using dependency managers like CocoaPods or Swift Package Manager.
# Via CocoaPods (in your Podfile)
pod 'Mixpanel-swift'
# Via Swift Package Manager (in Xcode: File > Add Packages...)
Refer to the Mixpanel iOS Swift Quickstart for detailed instructions specific to the iOS SDK.
Quickstart example
Once installed, initializing the SDK and tracking events typically involves a few lines of code. The following examples demonstrate basic initialization and event tracking for JavaScript and Python.
JavaScript (Web)
This example shows how to initialize Mixpanel and track a simple 'Page Viewed' event when a page loads, and a 'Button Clicked' event when a user interacts with a specific element.
import mixpanel from 'mixpanel-browser';
mixpanel.init('YOUR_PROJECT_TOKEN', {
debug: true,
track_pageview: true,
persistence: 'localStorage'
});
// Track an event on page load
mixpanel.track('Page Viewed', {
'Page Name': 'Homepage',
'URL': window.location.href
});
// Identify a user (optional, but recommended for user-level analysis)
mixpanel.identify('USER_ID_123');
mixpanel.people.set({
'$first_name': 'John',
'$last_name': 'Doe',
'$email': '[email protected]',
'Account Type': 'Premium'
});
// Example of tracking a button click
document.getElementById('myButton').addEventListener('click', () => {
mixpanel.track('Button Clicked', {
'Button Name': 'Call to Action',
'Location': 'Hero Section'
});
});
Python
This Python example demonstrates initializing the Mixpanel client and tracking a server-side event, such as a 'User Signed Up' event after successful registration.
from mixpanel import Mixpanel
# Initialize Mixpanel with your project token
mp = Mixpanel('YOUR_PROJECT_TOKEN')
# Track a server-side event
mp.track('USER_ID_456', 'User Signed Up', {
'Signup Method': 'Email',
'Plan Type': 'Free'
})
# Identify a user and set their properties
mp.people_set('USER_ID_456', {
'$first_name': 'Jane',
'$last_name': 'Smith',
'$email': '[email protected]',
'Subscription Status': 'Active'
})
These examples illustrate the core functionality of event tracking and user identification. For more advanced features, such as group analytics, funnel analysis, or A/B testing, consult the Mixpanel official documentation.
Community libraries
While Mixpanel provides official SDKs for major platforms, the community has also developed additional libraries and integrations. These community-driven projects can extend Mixpanel's functionality or offer solutions for languages and frameworks not officially supported. Examples of such contributions might include:
- GoLang Libraries: Unofficial Go clients for interacting with the Mixpanel API.
- Elixir Integrations: Modules designed for use within Elixir applications to send events to Mixpanel.
- CMS Plugins: Integrations for content management systems like WordPress or Drupal, simplifying Mixpanel setup without direct code modification.
- Framework-Specific Adapters: Libraries tailored for specific web frameworks (e.g., Vue.js plugins, Angular services) that wrap the official JavaScript SDK for easier use within that framework's ecosystem.
Developers considering community libraries should evaluate their maintenance status, documentation quality, and compatibility with the latest Mixpanel API versions. For critical applications, relying on Mixpanel's official SDKs is generally recommended due to direct support and guaranteed compatibility. The official Mixpanel blog sometimes highlights useful community contributions, providing a starting point for discovery Mixpanel API client libraries blog post.
It is also worth noting that many platforms, like Google Tag Manager, can be configured to send data to Mixpanel using custom HTML tags or pre-built templates, offering an alternative to direct SDK integration for web analytics implementation.