Documentation Index
Fetch the complete documentation index at: https://mintlify.com/mixpanel/docs/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Add dependency
Add to your app/build.gradle:dependencies {
implementation "com.mixpanel.android:mixpanel-android:7.+"
}
Sync Gradle
Click “Sync Project with Gradle Files” in Android Studio.
Add permissions
Add to your AndroidManifest.xml:<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
Initialize Mixpanel
import com.mixpanel.android.mpmetrics.MixpanelAPI;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MixpanelAPI mixpanel = MixpanelAPI.getInstance(
this,
"YOUR_PROJECT_TOKEN",
false // trackAutomaticEvents
);
}
}
Track Events
MixpanelAPI mixpanel = MixpanelAPI.getInstance(context, "YOUR_PROJECT_TOKEN", true);
JSONObject props = new JSONObject();
props.put("Gender", "Female");
props.put("Plan", "Premium");
mixpanel.track("Purchase", props);
Timing Events
mixpanel.timeEvent("Image Upload");
// 20 seconds later
if (imageUpload()) {
mixpanel.track("Image Upload");
}
Flush Events
// Flush immediately
mixpanel.flush();
// Set batch size
mixpanel.setFlushBatchSize(100);
Identify Users
// User signs in
mixpanel.track("sign in");
mixpanel.identify("12345");
Reset on Logout
mixpanel.track("log out");
mixpanel.reset();
User Profiles
mixpanel.identify("12345", true);
// Set single property
mixpanel.getPeople().set("plan", "Premium");
// Set multiple properties
JSONObject props = new JSONObject();
props.put("name", "John");
props.put("email", "john@example.com");
mixpanel.getPeople().set(props);
setOnce()
increment()
append()
union()
mixpanel.getPeople().setOnce("name", "John");
mixpanel.getPeople().setOnce("location", "US");
mixpanel.getPeople().increment("age", 1);
mixpanel.getPeople().increment("login_count", 1);
mixpanel.getPeople().append("roles", "admin");
mixpanel.getPeople().union("skills", new JSONArray().put("Java").put("Kotlin"));
Super Properties
JSONObject props = new JSONObject();
props.put("name", "John");
mixpanel.registerSuperProperties(props);
// Register without overwriting
JSONObject moreProps = new JSONObject();
moreProps.put("name", "Jane"); // Ignored
moreProps.put("city", "San Francisco"); // Set
mixpanel.registerSuperPropertiesOnce(moreProps);
Group Analytics
// Assign to group
mixpanel.setGroup("company", "Acme Inc");
// Track event (group included automatically)
mixpanel.track("feature_used");
// Set group properties
mixpanel.getGroup("company", "Acme Inc").set("industry", "Technology");
Privacy Controls
Opt Out
mixpanel.optOutTracking();
// Initialize with opt-out
boolean optOutTrackingDefault = true;
MixpanelAPI mixpanel = MixpanelAPI.getInstance(
context,
"YOUR_PROJECT_TOKEN",
optOutTrackingDefault,
false
);
EU Data Residency
Add to AndroidManifest.xml:
<application>
<meta-data
android:name="com.mixpanel.android.MPConfig.EventsEndpoint"
android:value="https://api-eu.mixpanel.com/track?ip=1" />
<meta-data
android:name="com.mixpanel.android.MPConfig.PeopleEndpoint"
android:value="https://api-eu.mixpanel.com/engage?ip=1" />
<meta-data
android:name="com.mixpanel.android.MPConfig.GroupsEndpoint"
android:value="https://api-eu.mixpanel.com/groups" />
</application>
Disable Geolocation
<meta-data
android:name="com.mixpanel.android.MPConfig.UseIpAddressForGeolocation"
android:value="false" />
Debug Mode
<application>
<meta-data
android:name="com.mixpanel.android.MPConfig.EnableDebugLogging"
android:value="true" />
</application>
- Events flush every 60 seconds or on app background
- Batch size: 50 events by default
- Requires Android API level 16+
- Supports App Links tracking
- Session Replay requires separate SDK
Resources