dart_mixpanel 0.0.1

Dart Mixpanel #

This library provides deep integration with your flutter and Mixpanel, in a similar way that Mixpanel's iOS and Android libraries do. Core features are:

  • Automatic Properties (first open, app updated, app session)
  • Mapping to Mixpanel endpoints for events and people properties
  • Automatically populates device and package info
  • Convenient API for timed events and navigation tracking
  • Support for integration testing by exposing all tracked events while in debug mode

Usage Example #

class MyAnalytics extends MixpanelAnalytics {
  static const bool debugAnalytics  = false;

  // Static methods don't support covariant, so we have to repeat this to get the proper type.
  static MyAnalytics of(BuildContext context) => MixpanelAnalytics.of(context);

  MyAnalytics(MixpanelStorage storage) : super(
    token: 'your-mixpanel-token',
    trackErrorHandler: (error, stackTrace, {endpoint, data}) => print('failed so send events'),
    storage: storage,

  // We could also call [track] directly, but this way our API is typed and all strings are in one place.
  Future<void> reportSaidHi(int intensity, {BuildContext context}) => track('said_hi', properties: {'intensity': intensity}, context: context);
  Future<void> reportImageUpload(Future action(), {BuildContext context}) => trackTimedAction('image_upload', action, context: context);

Future main() async {
  // These actions will likely finish well below a couple milliseconds, but are still defined
  // async and we need those to be ready when the app goes up, so do those before we start up
  // properly.
  final storage = MixpanelLocalStorage();
  await storage.init();
  final analytics = MyAnalytics(storage);
  await analytics.init();
  // If you do this on startup, you can later alias the user to their actual id and the
  // previous action will be attributed to the proper account.
  await analytics.setAnonymousUser();


class MyApp extends StatefulWidget {
  final MixpanelAnalytics analytics;
  const MyApp(this.analytics);

  _MyAppState createState() => _MyAppState();

class _MyAppState extends State<MyApp> {
  Widget build(BuildContext context) {
    return MixpanelAnalyticsProvider(
      analytics: widget.analytics,
      child: MaterialApp(
        navigatorObservers: [MixpanelAnalyticsObserver(widget.analytics)],
        home: MyWidget(),

class MyWidget extends StatelessWidget {
  Widget build(BuildContext context) {
    return FlatButton(child: Text('Hi'), onPressed: () {
      MyAnalytics.of(context).setUser('my-actual-user-id', properties: {'name': 'Bob'});

      // If you pass in the context, it will automatically try to find the name of the current route
      // that can be set via RouteSettings.name when you push a MaterialPageRoute
      MyAnalytics.of(context).reportSaidHi(7, context: context);

      // Timed action, event gets added a duration field
      MyAnalytics.of(context).reportImageUpload(() async {
        // await ...
      }, context: context);

Missing Features #

  • [ ] Offline buffering
  • [ ] Batched reporting (i.e. don't send each event immediately, but buffer a couple)
  • [ ] Retry strategies for network errors

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  dart_mixpanel: ^0.0.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:dart_mixpanel/flutter_integration.dart';
import 'package:dart_mixpanel/mixpanel_client.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 1, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Fix lib/flutter_integration.dart. (-0.50 points)

Analysis of lib/flutter_integration.dart reported 1 hint:

line 19 col 16: 'ancestorWidgetOfExactType' is deprecated and shouldn't be used. Use findAncestorWidgetOfExactType instead. This feature was deprecated after v1.12.1..

Format lib/mixpanel_client.dart.

Run flutter format to format lib/mixpanel_client.dart.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and dart_mixpanel.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-3 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
device_info ^0.4.0 0.4.2+1
flutter 0.0.0
http ^0.12.0 0.12.0+4
meta ^1.1.6 1.1.8
package_info ^0.4.0 0.4.0+16
shared_preferences ^0.5.3 0.5.6+3
uuid ^2.0.2 2.0.4
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.4
flutter_web_plugins 0.0.0
http_parser 3.1.4
path 1.6.4
pedantic 1.9.0
shared_preferences_macos 0.0.1+6
shared_preferences_platform_interface 1.0.3
shared_preferences_web 0.1.2+4
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8