Skip to main content

SDKs: Send Data from Your Application

Our SDKs allow you to implement Mixpanel in a wide range of environments. Visit our Github repo to see the library source code. If you do not see an SDK in your preferred language, leverage our HTTP APIs directly.

Client-Side SDKs

Client-side SDKs run in the user’s browser or on their mobile device, making it easy to track user interactions and automatically capture device information.

Javascript

Track events in web browsers with autocapture and session replay

React Native

Cross-platform mobile tracking for React Native apps

Android

Native Android SDK with replay and feature flags

iOS (Objective-C)

Legacy iOS SDK for Objective-C apps

iOS (Swift)

Modern Swift SDK with replay and feature flags

Flutter

Cross-platform tracking for Flutter applications

Unity

Game analytics for Unity game engine

JavaScript SDK Quick Start

The easiest way to get started with web tracking:
<!-- Paste this right before your closing 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))); }; } var a = b; "undefined" !== typeof c ? (a = b[c] = []) : (c = "mixpanel"); a.people = a.people || []; a.toString = function (a) { var d = "mixpanel"; "mixpanel" !== c && (d += "." + c); a || (d += " (stub)"); return d; }; a.people.toString = function () { return a.toString(1) + ".people (stub)"; }; i = "disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split(" "); for (h = 0; h < i.length; h++) g(a, i[h]); var j = "set set_once union unset remove delete".split(" "); a.get_group = function () { function b(c) { d[c] = function () { call2_args = arguments; call2 = [c].concat(Array.prototype.slice.call(call2_args, 0)); a.push([e, call2]); }; } for (var d = {}, e = ["get_group"].concat(Array.prototype.slice.call(arguments, 0)), c = 0; c < j.length; c++) b(j[c]); return d; }; b._i.push([e, f, c]); }; b.__SV = 1.2; e = f.createElement("script"); e.type = "text/javascript"; e.async = !0; e.src = "undefined" !== typeof MIXPANEL_CUSTOM_LIB_URL ? MIXPANEL_CUSTOM_LIB_URL : "file:" === f.location.protocol && "//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//) ? "https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js" : "//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js"; g = f.getElementsByTagName("script")[0]; g.parentNode.insertBefore(e, g); } })(document, window.mixpanel || []);

// Initialize Mixpanel
mixpanel.init("YOUR_PROJECT_TOKEN", {
    autocapture: true,
    track_pageview: true,
    record_sessions_percent: 100,
    record_heatmap_data: true,
});
</script>
Or install via NPM:
npm install --save mixpanel-browser
import mixpanel from 'mixpanel-browser'

mixpanel.init("YOUR_PROJECT_TOKEN", {
    autocapture: true,
    track_pageview: true,
});

// Track an event
mixpanel.track('Button Clicked', {
    'button_name': 'Sign Up',
    'page': 'Homepage'
});

Server-Side SDKs

Server-side SDKs are designed for backend environments where you have full control over the tracking logic. These SDKs are more reliable and not affected by ad-blockers.

Python

Server-side tracking for Python applications

Node.js

Async JavaScript tracking for Node.js servers

Ruby

Server-side tracking for Ruby applications

PHP

Server-side tracking for PHP applications

Go

High-performance tracking for Go applications

Java

Enterprise-grade tracking for Java applications

Python SDK Quick Start

pip install mixpanel
from mixpanel import Mixpanel

# Initialize Mixpanel
mp = Mixpanel("YOUR_PROJECT_TOKEN")

# Track an event
mp.track('12345', 'Sign Up', {
    'plan': 'premium',
    'source': 'landing_page'
})

# Set user profile properties
mp.people_set('12345', {
    'name': 'Sam Smith',
    '$email': '[email protected]',
}, meta={'$ip': 0})

Node.js SDK Quick Start

npm install mixpanel
const Mixpanel = require('mixpanel');

// Initialize Mixpanel
const mp = Mixpanel.init('YOUR_PROJECT_TOKEN');

// Track an event
mp.track('Sign Up', {
    distinct_id: '12345',
    plan: 'premium',
    source: 'landing_page'
});

// Set user profile properties
mp.people.set('12345', {
    'name': 'Sam Smith',
    '$email': '[email protected]'
});

Session Replay SDKs

Capture user sessions with video-like replay capabilities to understand exactly how users interact with your product.

Android Replay

Record and replay Android user sessions

Swift Replay

Record and replay iOS user sessions

JavaScript Replay

Record and replay web user sessions

React Native Replay

Record and replay React Native sessions

SDK Features

All SDKs support tracking custom events with properties. Events capture user actions and important moments in your product.
# Python example
mp.track('distinct_id', 'Video Watched', {
    'video_title': 'Getting Started',
    'duration': 120,
    'completion_rate': 0.85
})
Store demographic and behavioral data about your users with profile properties.
// JavaScript example
mixpanel.people.set({
    '$name': 'Jane Doe',
    '$email': '[email protected]',
    'plan_type': 'enterprise'
});
Link anonymous users to identified users as they sign up or log in.
// Track anonymous user
mixpanel.track('Page Viewed');

// User signs up - identify them
mixpanel.identify('user_123');

// Now all future events are tied to user_123
mixpanel.track('Button Clicked');
Analyze behavior at the account or company level with group analytics.
# Set group for an event
mp.track('user_123', 'Feature Used', {
    '$groups': {'company': 'acme_inc'}
})

# Set group properties
mp.get_group('company', 'acme_inc').set({
    'plan': 'enterprise',
    'industry': 'technology'
})
Automatically track clicks, page views, and form submissions without writing code.
mixpanel.init('YOUR_PROJECT_TOKEN', {
    autocapture: {
        pageview: 'full-url',
        click: true,
        submit: true,
        input: true,
        scroll: true
    }
});

API Endpoints by Data Residency

Ensure you configure your SDK to use the correct API host based on your project’s data residency:
Data ResidencyAPI HostConfiguration
US (default)api.mixpanel.comDefault - no configuration needed
EUapi-eu.mixpanel.comMust configure in SDK
Indiaapi-in.mixpanel.comMust configure in SDK
Projects with India Data Residency must configure SDKs with the api-in.mixpanel.com host or events will be rejected.

Utility Libraries

mixpanel-utils

Python utilities for data import, export, and transformation

Next Steps

View All SDK Docs

Detailed documentation for each SDK

Best Practices

Learn how to implement tracking correctly

Build docs developers (and LLMs) love