• Stars
    star
    1,017
  • Rank 45,237 (Top 0.9 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 14 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Official Android Tracking Library for Mixpanel Analytics

Mixpanel Android Library

Latest Version

April 28, 2023 - v7.3.1

Table of Contents

Quick Start Guide

Check out our official documentation for more in depth information on installing and using Mixpanel on Android.

1. Install Mixpanel

You will need your project token for initializing your library. You can get your project token from project settings.

Step 1 - Add the mixpanel-android library as a gradle dependency: We publish builds of our library to the Maven central repository as an .aar file. This file contains all of the classes, resources, and configurations that you'll need to use the library. To install the library inside Android Studio, you can simply declare it as dependency in your build.gradle file.

Add the following lines to the dependencies section in app/build.gradle

implementation "com.mixpanel.android:mixpanel-android:7.+"

Once you've updated your build.gradle file, you can force Android Studio to sync with your new configuration by clicking the Sync Project with Gradle Files icon at the top of the window.

Sync Android With Gradle

This should download the .aar dependency at which point you'll have access to the Mixpanel library API calls. If it cannot find the dependency, you should make sure you've specified mavenCentral() as a repository in your build.gradle.

Step 2 - Add permissions to your AndroidManifest.xml: In order for the library to work you'll need to ensure that you're requesting the following permissions in your AndroidManifest.xml:

<!--
This permission is required to allow the application to send
events and properties to Mixpanel.
-->
<uses-permission
  android:name="android.permission.INTERNET" />

<!--
  This permission is optional but recommended so we can be smart
  about when to send data.
 -->
<uses-permission
  android:name="android.permission.ACCESS_NETWORK_STATE" />

<!--
  This permission is optional but recommended so events will
  contain information about bluetooth state
-->
<uses-permission
  android:name="android.permission.BLUETOOTH" />

At this point, you're ready to use the Mixpanel Android library inside Android Studio.

2. Initialize Mixpanel

Once you've set up your build system or IDE to use the Mixpanel library, you can initialize it in your code by calling MixpanelAPI.getInstance with your application context, your Mixpanel project token and automatic events setting. You can find your token in project settings.

import com.mixpanel.android.mpmetrics.MixpanelAPI;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        trackAutomaticEvents = true;
        MixpanelAPI mixpanel = MixpanelAPI.getInstance(this, "YOUR_TOKEN", trackAutomaticEvents);
    }
}

See all configuration options

3. Send Data

Let's get started by sending event data. You can send an event from anywhere in your application. Better understand user behavior by storing details that are specific to the event (properties). After initializing the library, Mixpanel will automatically collect common mobile events. You can enable/disable automatic collection through your project settings. Also, Mixpanel automatically tracks some properties by default. learn more

JSONObject props = new JSONObject();
props.put("source", "Pat's affiliate site");
props.put("Opted out of email", true);

mixpanel.track("Sign Up", props);

In addition to event data, you can also send user profile data. We recommend this after completing the quickstart guide.

4. Check for Success

Open up the Events report (formerly Live View) in Mixpanel to view incoming events.

Once data hits our API, it generally takes ~60 seconds for it to be processed, stored, and queryable in your project.

πŸ‘‹ πŸ‘‹ Tell us about the Mixpanel developer experience! https://www.mixpanel.com/devnps πŸ‘ πŸ‘Ž

FAQ

I want to stop tracking an event/event property in Mixpanel. Is that possible?

Yes, in Lexicon, you can intercept and drop incoming events or properties. Mixpanel won’t store any new data for the event or property you select to drop. See this article for more information.

I have a test user I would like to opt out of tracking. How do I do that?

Mixpanel’s client-side tracking library contains the optOutTracking() method, which will set the user’s local opt-out state to β€œtrue” and will prevent data from being sent from a user’s device. More detailed instructions can be found in the section, Opting users out of tracking.

Why aren't my events showing up?

First make sure your test device has internet access. To preserve battery life and customer bandwidth, the Mixpanel library doesn't send the events you record immediately. Instead, it sends batches to the Mixpanel servers every 60 seconds while your application is running, as well as when the application transitions to the background. You can call flush() manually if you want to force a flush at a particular moment for example before your application is completely shutdown.

If your events are still not showing up after 60 seconds, check if you have opted out of tracking. You can also enable Mixpanel debugging and logging, it allows you to see the debug output from the Mixpanel Android library. To enable it, you will want to add the following permission within your AndroidManifest.xml inside the <application> tag:

...
<application>
    <meta-data
      android:name="com.mixpanel.android.MPConfig.EnableDebugLogging"
      android:value="true" />
    ...
</application>
...

Other common issues

People.set throwing UnsupportedOperationException

I want to know more!

No worries, here are some links that you will find useful:

Have any questions? Reach out to [email protected] to speak to someone smart, quickly.

Want to Contribute?

The Mixpanel library for Android is an open source project, and we'd love to see your contributions! We'd also love for you to come and work with us! Check out our opening positions for details.

Changelog

See changelog.

License

See LICENSE File for details. The Base64Coder,
ConfigurationChecker, and StackBlurManager classes, and the entirety of the
 com.mixpanel.android.java_websocket package used by this
software have been licensed from non-Mixpanel sources and modified
for use in the library. Please see the relevant source files, and the
LICENSE file in the com.mixpanel.android.java_websocket package for details.

The StackBlurManager class uses an algorithm by Mario Klingemann <[email protected]>
You can learn more about the algorithm at
http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html.

More Repositories

1

mixpanel-iphone

Official iOS (Objective-C) Tracking Library for Mixpanel Analytics
Objective-C
1,027
star
2

mixpanel-js

Official Mixpanel JavaScript Client Library
JavaScript
823
star
3

mixpanel-node

A node.js API for mixpanel
JavaScript
463
star
4

mixpanel-swift

Official iOS (Swift) Tracking Library for Mixpanel Analytics
Swift
395
star
5

panel

Web Components + Virtual DOM: web standards for powerful UIs
JavaScript
273
star
6

mixpanel-ruby

Ruby
170
star
7

mixpanel-php

PHP
134
star
8

mixpanel-react-native

Official React Native Tracking Library for Mixpanel Analytics
JavaScript
103
star
9

mixpanel-python

Official Mixpanel Python library.
Python
101
star
10

mixpanel-utils

Python
80
star
11

mixpanel-flutter

Official Flutter Tracking Library for Mixpanel Analytics
Dart
66
star
12

sample-android-mixpanel-integration

Java
55
star
13

tracking-proxy

One-click configuration to proxy tracking requests to Mixpanel's API
Dockerfile
49
star
14

mixpanel-java

Java
48
star
15

mixpanel-unity

Official Unity Tracking Library for Mixpanel Analytics
C#
37
star
16

docs

Mixpanel's Official Documentation
MDX
35
star
17

fuzzbunny

Fast fuzzy string searching/matching/highlighting
JavaScript
19
star
18

panel-farm

Manage cute animals with Web Components and Virtual DOM very wow
JavaScript
10
star
19

snabbdom-jsx-lite

Write snabbdom templates in .jsx or .tsx (JSX for TypeScript)
TypeScript
10
star
20

flask-tracking-proxy

Example Python Flask application to proxy tracking requests to Mixpanel's API
Python
10
star
21

configmanager

A library for adding dynamic configuration to your code
Go
9
star
22

webcomponent

Lightweight utilities for constructing web components
JavaScript
8
star
23

webpack-dev-server-status-bar

Unobtrusive HTML status indicator for Webpack compilation status
JavaScript
7
star
24

mixpanel-gtm-template

A GitHub project created under the Mixpanel organization to store the Mixpanel GTM template
Smarty
6
star
25

obs

Opinionated observability package that combines logging, tracing and metrics.
Go
6
star
26

mixpanel-go

Mixpanel Official Go SK
Go
4
star
27

framesg

request/response communication to/from iframes
JavaScript
4
star
28

sheets

πŸ”„ integrate mixpanel with google sheets
JavaScript
3
star
29

mixpanel-chrome-extension

This extension will inject the Mixpanel library into every page you visit
JavaScript
3
star
30

domsuite

JavaScript browser testing/automation utilities with async/await
JavaScript
2
star
31

mixpanel-js-wrapper

A GitHub project created under the Mixpanel organization to store the Mixpanel JS wrapper
JavaScript
2
star
32

django-prefetch-example

Python
1
star
33

dedupe-chunks-webpack-plugin

(make public later)
JavaScript
1
star