Skip to content

Latest commit

 

History

History
111 lines (78 loc) · 3.29 KB

README.md

File metadata and controls

111 lines (78 loc) · 3.29 KB

MTC Logo

Pub.dev Badge MIT License Badge Flutter Platform Badge

MTC - Analytics

All in one. This package was created to simplify the job of logging events across different analytics platforms.

Getting Started

Amplitude

If you want to use Amplitude in iOS, you need to add platform :ios, '10.0' to your Podfile.

Amplitude - Documentation

Firebase Analytics

To use Firebase Analytics, you need to add your app to your Firebase project in the Firebase console. Firebase - Documentation

Features

With this package you'll can:

  • Use built-in trackers or add new trackers that you need in your application.
  • Configure User properties
  • Log Events and Event properties

Usage

Initialization

Before try to set user properties or track any event, you must initialize the AnalyticsService with according trackers.

List<Tracker> trackers = [MyCustomTracker()];

AnalyticsService analyticsService = AnalyticsService.instance;
analyticsService.init(trackers);

At this time, we already implemented a ConsoleTracker for debugging purpose, AmplitudeTracker and FirebaseTracker. You can use them

List<Tracker> trackers = [
    MyCustomTracker(),
    ConsoleTracker(),
    AmplitudeTracker(apiKey: 'api-key'),
    FirebaseTracker(),
];

AnalyticsService analyticsService = AnalyticsService.instance;
analyticsService.init(trackers);

Set user properties

To set user properties simply call AnalyticsService.instance.setUserProperties

AnalyticsService.instance.setUserProperties(
    {
        "name": "MTC - Flutter Team",
        "email": "[email protected]",
    },
);

Log events

To log events you need to create you own event class. For example, if the app needs to log an event when the user increments a counter:

class IncrementCounterEvent extends Event {
  final int count;

  IncrementCounterEvent({required this.count})
      : super(
          name: 'increment_count',
          properties: {'count': count},
        );
}

After that, you can call AnalyticsService.instance.track and pass it the created event

AnalyticsService.instance.track(
    IncrementCounterEvent(count: _counter),
);

Additional information

Visit our page to know more about us!

If our content like you can help us with a coffee to continue creating and collaborating with the Flutter community

Buy a coffe button