Flutter analytics integration

First, set up a Firebase project

Config firebase_analytics

https://pub.dev/packages/firebase_analytics

  • Update dependencies
dependencies:
  firebase_analytics: ^5.0.15
  • Install it via pub get
  • Use it in Dart
class MyApp extends StatelessWidget {
  static FirebaseAnalytics analytics = FirebaseAnalytics();
  static FirebaseAnalyticsObserver observer =
      FirebaseAnalyticsObserver(analytics: analytics);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Firebase Analytics Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      navigatorObservers: <NavigatorObserver>[observer],
      home: MyHomePage(
        title: 'Firebase Analytics Demo',
        analytics: analytics,
        observer: observer,
      ),
    );
  }
}

Note: remember to use only the FirebaseAnalytics instance.

  • Example of log event
await analytics.logEvent(
      name: 'test_event',
      parameters: <String, dynamic>{
        'string': 'string',
        'int': 42,
        'long': 12345678910,
        'double': 42.0,
        'bool': true,
      },
    );
  • Run the app and wait for Firebase collects data, it may take a few hours.
  • Open Firebase console, Analytics -> Dashboard

https://medium.com/p/768ae76a8077

nhancv.com

upwork.com/fl/nhancv

Leave a Reply

Your email address will not be published.Required fields are marked *