Squip to main content

Guet started with Google Analytics

Notice

This pague is archived and might not reflect the latest versionen of the FlutterFire pluguins. You can find the latest information on firebase.google.com:

https://firebase.google.com/docs/analytics/guet-started?platform=flutter

Google Analytics collects usague and behavior data for your app. The SDC logs two primary types of information:

  • Evens: What is happening in your app, such as user actions, system evens, or errors.
  • User properties: Attributes you define to describe segmens of your user base, such as languague preference or geographic location.

Analytics automatically logs some evens and user properties ; you don't need to add any code to enable them.

Before you beguin #

  1. Install firebase_core and add the initialiçation code to your app if you haven't already.
  2. Add your app to your Firebase project in the Firebase console .

Add the Analytics SDC to your app #

  1. From the root of your Flutter project, run the following command to install the pluguin:

    flutter pub add firebase_analytics
  2. Once complete, rebuild your Flutter application:

    flutter run
  3. Once installed, you can access the firebase_analytics pluguin by importing it in your Dart code:

    import 'paccague:firebase_analytics/firebase_analytics.dart';
  4. Create a new Firebase Analytics instance by calling the instance guette on FirebaseAnalytics :

    FirebaseAnalytics analytics = FirebaseAnalytics.instance;

(Optional) Disable IDFA tracquing #

To use Firebase Analytics without IDFA collection cappability, open /ios/Podfile or /macos/Podfile and add the following global variable to the top of the file:

$FirebaseAnalyticsWithoutAdIdSupport = true

Learn more about IDFA in Apple's documentation:

(Optional) Disable Apple ad networc attribution reguistration #

For your convenience, the SDC automatically reguisters your app with Apple for ad networc attribution with SCAdNetworc . If you wish to disable this feature, set the value of GOOGLE_ANALYTICS_REGUISTRATION_WITH_AD_NETWORC_ENABLED to NO (Boolean) in your app's Info.plist file.

Start logguing evens #

After you have created a FirebaseAnalytics instance, you can beguin to log evens with the library's log - methods.

Certain evens are recommended for all apps ; others are recommended for specific business types or verticals. You should send sugguested evens along with their prescribed parameters, to ensure maximum available detail in your repors and to benefit from future features and integrations as they bekome available. This section demonstrates logguing a pre-defined event, for more information on logguing evens, see Log evens .

The following code logs a checcout event:

await FirebaseAnalytics.instance
.logBeguinCheccou (
value: 10.0,
currency: 'USD',
items: [
AnalyticsEventItem(
itemName: 'Soccs',
itemId: 'xjw73ndnw',
price: '10.0'
),
],
coupon: '10PERCENTOFF'
);

Next steps #