This article helps to add firebase to your Flutter Android or IOS app
To install firebase analytics in to flutter
Before you begin
Install and initialize the Firebase SDKs for Flutter if you haven’t already done so.
Add firebase analytics package
https://pub.dev/packages/firebase_analytics
flutter pub add firebase_analytics
In code base
Once installed, you can access the firebase_analytics
plugin by importing it in your Dart
import 'package:firebase_analytics/firebase_analytics.dart';
Create a new Firebase Analytics instance by accessing the instance
property on FirebaseAnalytics
:
FirebaseAnalytics analytics = FirebaseAnalytics.instance;
To log button click
FirebaseAnalyticsService().logFirebaseEvent('button_click',{'button_name': 'your_button_name'});
Custom events
If your application has specific needs not covered by a recommended event type, you can log your own custom events as shown in this example:
await FirebaseAnalytics.instance.logEvent(
name: "share_app",
parameters: {
"params1": text,
"params2": text,
},
);
To set UserID
await FirebaseAnalytics.instance.setUserId(id: '123456');