Flutter analytics integration

First, set up a Firebase project

Config firebase_analytics


  • Update dependencies
  firebase_core: ^0.5.0
  firebase_analytics: ^6.0.1
  • Install it via pub get
  • Need to update Android configs
1. Update android/build.gradle
buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath 'com.google.gms:google-services:4.3.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

2. Update android/app/build.gradle.

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics:17.5.0'

apply plugin: 'com.google.gms.google-services'
  • Use it in Dart
class MyApp extends StatelessWidget {
  static FirebaseAnalytics analytics = FirebaseAnalytics();
  static FirebaseAnalyticsObserver observer =
      FirebaseAnalyticsObserver(analytics: analytics);

  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




Leave a Reply

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