This quickstart shows you how to add Google Analytics to your app and begin logging events.
Google Analytics collects usage and behavior data for your app. The SDK logs two primary types of information:
- Events: What is happening in your app, such as user actions, system events, or errors.
- User properties: Attributes you define to describe segments of your user base, such as language preference or geographic location.
Before you begin
firebase_coreand add the initialization code to your app if you haven't already.
- Add your app to your Firebase project in the Firebase console.
Add the Analytics SDK to your app
From the root of your Flutter project, run the following command to install the plugin:
flutter pub add firebase_analytics
Once complete, rebuild your Flutter application:
Once installed, you can access the
firebase_analyticsplugin by importing it in your Dart code:
Create a new Firebase Analytics instance by calling the
FirebaseAnalytics analytics = FirebaseAnalytics.instance;
Start logging events
After you have created a
FirebaseAnalytics instance, you can begin to log
events with the library's
Certain events are recommended for all apps; others are recommended for specific business types or verticals. You should send suggested events along with their prescribed parameters, to ensure maximum available detail in your reports and to benefit from future features and integrations as they become available. This section demonstrates logging a pre-defined event, for more information on logging events, see Log events.
The following code logs a checkout event:
await FirebaseAnalytics.instance .logBeginCheckout( value: 10.0, currency: 'USD', items: [ AnalyticsEventItem( itemName: 'Socks', itemId: 'xjw73ndnw', price: '10.0' ), ], coupon: '10PERCENTOFF' );
- Use the DebugView to verify your events.
- Explore your data in the Firebase console.
- Explore the guides on events and user properties.
- Learn how to export your data to BigQuery.