Firebase Analytics for Android: Step-by-Step Setup Guide

Firebase Analytics for Android: Step-by-Step Setup Guide: GA4 & analytics article cover from AnalyticsLiv

In short

To add Firebase Analytics to an Android app, create a Firebase project linked to a GA4 property, register the app's package name, put google-services.json in the app module and add the Google services plugin and Firebase BoM to Gradle. Then log custom events with logEvent and check them in DebugView before they reach GA4 reports.

Contents7 sections

Talk to a specialist

Firebase Analytics (Google Analytics for Firebase) sends your app's events to Google Analytics 4, so you can see how people use your Android app and improve it. This step-by-step guide covers creating the Firebase project, registering the app, adding the config file and Gradle setup, logging custom events and testing them in DebugView.

Firebase Analytics works in Android, iOS and web apps. Here we focus on Android.

Step 1: Create a Firebase project

  1. In the Firebase console, click Add project, then select or enter a project name. If you have an existing Google Cloud project, you can select it from the dropdown to add Firebase resources to that project.
  2. (Optional) If you are creating a new project, you can edit the project ID. Firebase assigns a unique ID automatically. See Understand Firebase projects for how Firebase uses it.
Creating a project in the Firebase console
  1. Click Continue.
Enabling Google Analytics for the Firebase project
  1. Choose an existing Google Analytics account or create a new one, choose the GA4 property, then click Create project.

Firebase provisions resources for the project and then opens its overview page in the Firebase console.

Firebase project overview page

Step 2: Register the app with Firebase

  1. Go to the Firebase console.
  2. On the project overview page, click the Android icon or Add app to start the setup workflow.
  3. Enter your app's package name in the Android package name field.
  4. (Optional) Enter an app nickname and the debug signing certificate SHA-1.
  5. Click Register app.
Registering an Android app in Firebase

Step 3: Add the config file and Gradle setup

  1. Click Download google-services.json and place the file in your app module (app-level) directory.
  2. Add the Google services Gradle plugin, which makes the values in google-services.json available to the Firebase SDKs. In your root-level (project-level) Gradle file, build.gradle.kts:
plugins {
  // ...
  // Add the dependency for the Google services Gradle plugin
  id("com.google.gms.google-services") version "4.5.0" apply false
}
  1. In your module (app-level) Gradle file, usually app/build.gradle.kts, apply the plugin:
plugins {
  id("com.android.application")
  // Add the Google services Gradle plugin
  id("com.google.gms.google-services")
}
  1. In the same module-level file, add the Analytics library. Google recommends the Firebase Android BoM, which keeps your Firebase library versions compatible, so you don't set a version on each library:
dependencies {
  // Import the Firebase BoM
  implementation(platform("com.google.firebase:firebase-bom:35.1.0"))

  // Add the dependency for the Firebase SDK for Google Analytics
  implementation("com.google.firebase:firebase-analytics")

  // Add the dependencies for any other Firebase products you want to use
}

The version numbers above are current at the time of writing. Check the Firebase Android setup guide for the latest versions and the Groovy syntax if your project uses build.gradle files. Then sync your project in Android Studio.

Step 4: Log custom events

  1. Once the SDK is added, Firebase starts recording automatically collected events such as screen_view, first_open, session_start, app_remove and app_update. See the full list of automatically collected events.
  2. Get a FirebaseAnalytics instance in your activity's onCreate(): mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); in Java, or firebaseAnalytics = Firebase.analytics in Kotlin.
  3. Log your own events. In this example, the app logs an event when a user taps the share image option:
Bundle params = new Bundle();
params.putString("screen_name", screenName);
params.putString("image_name", name);
params.putString("full_text", text);
mFirebaseAnalytics.logEvent("share_image", params);

How do you test Firebase events?

Test in two places: the Android Studio log and DebugView.

  1. Android Studio: with verbose logging enabled, check that the custom event and its parameters appear in Logcat when you perform the action in the app.
Firebase event logged in Android Studio Logcat
  1. DebugView: enable debug mode on your test device with adb shell setprop debug.firebase.analytics.app PACKAGE_NAME, then open Analytics > DebugView in the Firebase console. You see events and their parameters in real time, so you can confirm they are recorded correctly and fix any that aren't. Turn debug mode off with adb shell setprop debug.firebase.analytics.app .none.
Firebase DebugView showing events in real time

Where do Firebase events appear in reports?

After processing, your events appear in the Firebase console and in the linked GA4 property's reports.

Firebase events in reports
Event parameters in Firebase reports

To use these events as app conversions, mark the important ones as key events in GA4. Our guide to app conversion tracking with GA4 and Firebase covers this.

Summary

To set up Firebase Analytics on Android, create a Firebase project linked to GA4, register your app, add google-services.json and the Gradle plugin and BoM, log custom events with logEvent and test them in DebugView. Firebase then reports your app's events in Firebase and GA4.

Watch the video for this post: youtube.com/embed/8nZTRoU_heY

Frequently asked questions.

Ask us your own question

Enable debug mode with adb shell setprop debug.firebase.analytics.app PACKAGE_NAME, then open Analytics > DebugView in the Firebase console to see events and parameters in real time. You can also check Logcat in Android Studio.

Not if you use the Firebase Android BoM. Import the BoM with a version, and the firebase-analytics dependency takes its version from it.

Once the SDK is added, Firebase records events such as screen_view, first_open, session_start, app_remove and app_update without extra code.

Tracking an app or a product?

Talk to the team that sets up Firebase, Mixpanel, AppsFlyer and Adjust on one event plan.