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();

  runApp(MyApp(analytics));
}

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

  @override
  _MyAppState createState() => _MyAppState();
}

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

class MyWidget extends StatelessWidget {
  @override
  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:


dependencies:
  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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
57
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

We analyzed this package on Oct 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/flutter_integration.dart.

Run flutter format to format lib/flutter_integration.dart.

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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
device_info ^0.4.0 0.4.1
flutter 0.0.0
http ^0.12.0 0.12.0+2
meta ^1.1.6 1.1.7
package_info ^0.4.0 0.4.0+9
shared_preferences ^0.5.3 0.5.4
uuid ^2.0.2 2.0.2
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.3
http_parser 3.1.3
path 1.6.4
pedantic 1.8.0+1
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8