mixpanel_flutter 2.3.0 copy "mixpanel_flutter: ^2.3.0" to clipboard
mixpanel_flutter: ^2.3.0 copied to clipboard

Official Flutter Tracking SDK for Mixpanel Analytics developed and maintained by Mixpanel, Inc.

Mixpanel Flutter SDK

Table of Contents #

Introduction #

Welcome to the official Mixpanel Flutter SDK. The Mixpanel Flutter SDK 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 Jobs for details

Quick Start Guide #

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

1. Install Mixpanel #

Prerequisites #

Steps #

  1. Depend on it
    Add this to your package's pubspec.yaml file:
   dependencies:
      mixpanel_flutter: ^1.x.x # set this to your desired version
  1. Install it
    You can install packages from the command line:
   $ flutter pub get
  1. Import it
    Now in your Dart code, you can use:
import 'package:mixpanel_flutter/mixpanel_flutter.dart';

Flutter Web Support

Please add the following snippet to your web/index.html inside <head></head> in your Flutter project.

<script src="./assets/packages/mixpanel_flutter/assets/mixpanel.js"></script>

2. Initialize Mixpanel #

To start tracking with the SDK you must first initialize with your project token. To initialize the SDK, first add import 'package:mixpanel_flutter/mixpanel_flutter.dart'; and call Mixpanel.init(token, trackAutomaticEvents); with your project token and automatic events setting as it's arguments. You can find your token in project settings.

import 'package:mixpanel_flutter/mixpanel_flutter.dart';
...
class _YourClassState extends State<YourClass> {
  Mixpanel mixpanel;

  @override
  void initState() {
    super.initState();
    initMixpanel();
  }

  Future<void> initMixpanel() async {
    mixpanel = await Mixpanel.init("Your Mixpanel Token", trackAutomaticEvents: false);
  }
...

Once you've called this method once, you can access mixpanel throughout the rest of your application.

3. Send Data #

Once you've initialized the SDK, Mixpanel will automatically collect common mobile events. You can enable/disable automatic collection through your project settings. With the mixpanel object created in the last step a call to track is all you need to send additional events to Mixpanel.

// Track with event-name
mixpanel.track('Sent Message');
// Track with event-name and property
mixpanel.track('Plan Selected', properties: {'Plan': 'Premium'});

You're done! You've successfully integrated the Mixpanel Flutter SDK into your app. To stay up to speed on important SDK releases and updates, star or watch our repository on Github.

4. Check for Success #

Open up Events 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.

mixpanel.flush();

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 library. To enable it, call setLoggingEnabled to true, then run your iOS project with Xcode or android project with Android Studio. The logs should be available in the console.

mixpanel.setLoggingEnabled(true);

Starting with iOS 14.5, do I need to request the user’s permission through the AppTrackingTransparency framework to use Mixpanel?

No, Mixpanel does not use IDFA so it does not require user permission through the AppTrackingTransparency(ATT) framework.

If I use Mixpanel, how do I answer app privacy questions for the App Store?

Please refer to our Apple App Developer Privacy Guidance

I want to know more! #

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

Have any questions? Reach out to Mixpanel Support to speak to someone smart, quickly.

109
likes
130
pub points
98%
popularity

Publisher

unverified uploader

Official Flutter Tracking SDK for Mixpanel Analytics developed and maintained by Mixpanel, Inc.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

Apache-2.0 (LICENSE)

Dependencies

flutter, flutter_web_plugins, js

More

Packages that depend on mixpanel_flutter