How to Implement Google Analytics in Android

Cody Schneider9 min read

Adding analytics to your Android app lets you see how people actually use it, giving you the insights needed to create an app that people love. This guide will walk you through the entire process of implementing Google Analytics in your Android project, from initial setup to logging custom events and viewing your data.

What is Google Analytics for Firebase?

First, let's clear up a common point of confusion. If you've worked with Google Analytics on the web, you might be looking for a separate "Google Analytics SDK" for Android. In the past, this existed. Today, the recommended and official way to use Google Analytics in a mobile app (both Android and iOS) is through the Firebase platform.

Firebase is Google's mobile development platform that provides a suite of tools for building, improving, and growing your app. Google Analytics is one of its core, foundational features. When you integrate the Firebase SDK, you're getting Google Analytics 4 capabilities built specifically for mobile apps. This is great news because it simplifies setup and gives you access to a powerful set of app-centric features right away.

By implementing it, you can understand:

  • How many users you have and where they come from.
  • Which screens or features are most popular.
  • What actions users take within your app.
  • User demographics like age, gender, and interests.
  • App stability, by tracking crashes and errors.

Armed with this data, you can stop guessing and start making informed decisions to improve user onboarding, increase engagement, and drive business goals.

Step 1: Create a Firebase Project

Before you write a single line of code, you need a Firebase project to connect your app to. This project will serve as a container for your app's Firebase services, including Analytics.

  1. Navigate to the Firebase console.
  2. Click "Add project" and give your project a memorable name (e.g., "My Awesome App Analytics").
  3. On the next screen, you’ll be prompted to set up Google Analytics for your project. This is enabled by default - leave it on! This is the most crucial step. Click "Continue."
  4. You'll be asked to configure Google Analytics. If you have an existing GA4 account and property you want to connect to, you can select it. Otherwise, you can create a new one. Choose an Analytics location and accept the terms.
  5. Click "Create project." Firebase will take a moment to provision your new project.

Once your project is ready, you'll be taken to its dashboard. From here, you're ready to register your Android app.

Step 2: Register Your App with Firebase

Now you need to tell Firebase about your specific Android application so it knows where to expect data from.

  1. On the Firebase project dashboard, click the Android icon (it looks like the little robot) to start the setup workflow.
  2. You will be asked for your app's "Android package name." This is critical and must be correct. You can find it in your app-level build.gradle file, listed under applicationId. Copy and paste it exactly.
  3. You can also provide an "App nickname" (optional, for your own reference) and a "Debug signing certificate SHA-1" (optional, but needed for other services like Google Sign-In or Phone Auth). For a basic Analytics setup, you can skip the SHA-1 key for now.
  4. Click "Register app."

Step 3: Add the Firebase Configuration File

After registering your app, Firebase will generate a special configuration file named google-services.json. This file contains all the unique identifiers your app needs to securely connect to your Firebase project.

  1. Click "Download google-services.json" to save the file to your computer.
  2. Switch over to your project in Android Studio. Ensure you are in the "Project" view (you can select this from the dropdown menu at the top left of the Project tool window).
  3. Drag and drop the downloaded google-services.json file into your app's module directory, which is usually YourProjectName/app.

If you put this file in the wrong place, the connection will fail, so double-check that its final path is something like /app/google-services.json.

Step 4: Add the Firebase SDKs to Your App

Next, you need to add the code libraries (SDKs) to your app that handle all the communication with Firebase and Google Analytics. This is done through your project's Gradle files.

1. Modify Your Project-Level Gradle File

Open the build.gradle file for your project (this is the one in the root directory).

Make sure you have Google's Maven repository listed under buildscript and allprojects repositories.

Then, add the Google Services plugin to the dependencies block inside buildscript:

buildscript {
    dependencies {
        // ... other dependencies
        classpath 'com.google.gms:google-services:4.4.2'
    }
}

2. Modify Your App-Level Gradle File

Now open the build.gradle file for your app module (the one inside the /app folder).

First, apply the Google Services plugin at the top of the file, typically after the com.android.application plugin:

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}

Next, add the Firebase Bill of Materials (BoM) to your dependencies block. The BoM intelligently manages the versions of all your Firebase libraries to ensure they are compatible. Then, add the dependency for the Google Analytics itself.

dependencies {
    // ... other dependencies

    // Import the Firebase BoM
    implementation(platform("com.google.firebase:firebase-bom:33.1.2"))

    // Add the dependency for the Google Analytics library
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation("com.google.firebase:firebase-analytics-ktx")
}

After adding this code, Android Studio will prompt you to sync your project. Click "Sync Now." Gradle will download and add the required SDKs to your project. And that's it! By adding the dependency, Google Analytics is now enabled. You'll automatically start getting basic engagement events and user session data without writing any more code.

Step 5: How to Log Events

Automatic tracking is great, but the real power of analytics comes from tracking events that are specific to your app's functionality. An "event" is any meaningful user interaction, like clicking a button, completing a level, or making a purchase.

To log events, you first need to get an instance of the FirebaseAnalytics class. It's best to declare this at the top of your Activity or Fragment.

import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.ktx.Firebase

private lateinit var firebaseAnalytics: FirebaseAnalytics

// ...

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    // ...
    // Obtain the FirebaseAnalytics instance.
    firebaseAnalytics = Firebase.analytics
}

Now, you can use the firebaseAnalytics object to log different types of events.

Automatic Events and Recommended Events

Firebase Analytics automatically collects a handful of events right out of the box, such as first_open, session_start, and screen_view. The screen_view event is particularly useful, as it tracks which screens users are visiting without any configuration on your part.

In addition, Google provides a list of recommended events for common scenarios (ecommerce, games, etc.). It's always a good practice to use these when they fit your needs, as they automatically create more detailed reports inside Analytics.

For example, to log a standard "select content" event when a user clicks on an item in a list:

val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "product_123")
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "Green Running Shoes")
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "product")
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle)

Logging Custom Events

For actions unique to your app, you can create your own custom events. Let's say we want to track when a user shares a piece of content using a share button.

You can define your own event name and parameters. Event names can be up to 40 characters long, must start with a letter, and can only contain letters, numbers, and underscores.

// When a user clicks the share button
val shareButton = findViewById<Button>(R.id.share_button)
shareButton.setOnClickListener {
    val bundle = Bundle()
    bundle.putString("share_method", "whatsapp")
    bundle.putString("content_id", "article_101")
    firebaseAnalytics.logEvent("share_content", bundle)
}

In this example, we've created a custom event called share_content and attached two parameters: the method they used to share and the ID of the shared content. You can see these custom parameters in your Analytics reports once you register them in the Firebase console (under Analytics > Custom Definitions).

Step 6: Set User Properties

While events track what users do, user properties describe who users are. These are attributes you can set to define segments of your user base, such as plan_type, user_language, or favorite_genre.

You can set user properties at any point. For example, after a user sets their language preference, you could log it like this:

firebaseAnalytics.setUserProperty("user_language", "en-us")

Once set, this property will be attached to all future events logged by that user (until it's changed or cleared). This lets you filter your event reports by user properties. For instance, you could compare the purchase behavior of "free_tier" users versus "premium_tier" users.

Step 7: Verify Your Implementation with DebugView

Waiting up to 24 hours for events to appear in the dashboard can be frustrating during development. Luckily, Firebase provides a fantastic tool called DebugView that shows you a real-time stream of events from your debug device.

To enable DebugView, connect your device or emulator and run a single command in the Android Studio terminal:

adb shell setprop debug.firebase.analytics.app [YOUR_APP_PACKAGE_NAME]

After running this, go to the Firebase Console, navigate to Analytics > DebugView. Now, as you use your app and trigger events, you'll see them appear in this dashboard within seconds. It's the perfect way to confirm that your events and parameters are being logged correctly before you deploy your app.

To turn it off, run:

adb shell setprop debug.firebase.analytics.app .none.

Final Thoughts

Getting started with Google Analytics in an Android app is an incredibly valuable step towards building a successful product. By leveraging the Firebase platform, you can quickly integrate a powerful analytics tool that automatically gathers baseline metrics and allows for deep customization through custom events and user properties, helping you truly understand your users.

Once you are collecting this valuable app data, the next step is often to combine it with a complete view of your business. We built Graphed to help with exactly this. By connecting your Google Analytics data along with sources like your ad platforms, CRM, and storefront, we enable you to instantly build comprehensive dashboards using natural language. You can just ask questions like "show me customer lifetime value by acquisition channel across web and app" and get a unified, real-time report in seconds.

Related Articles

How to Connect Facebook to Google Data Studio: The Complete Guide for 2026

Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.

Appsflyer vs Mixpanel​: Complete 2026 Comparison Guide

The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.