How To Add Firebase Analytics To Android

April 18, 2018

Step 1: Add Firebase To Android.

Edit module/app build.gradle.

dependencies {
    implementation ''

NOTE: is a recommended alias for the library.

Once you included, Firebase Analytics automatically track all activty view event (you don’t have to write any code).

If you need to log custom events

val analytics = FirebaseAnalytics.getInstance(this)

val bundle = Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, id)
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name)
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image")

analytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle)

NOTE: I have yet to deeper than activity event logging, so refer to Firebase Analytics Doc for more info.

Disable Analytics For Debug Build

I believe Firebase Analytics is enabled by default, even for Debug build.

To disable analytics for Debug build, edit app/module build.gradle.

android {
    // ...
    buildTypes {
        debug {
            // manifestPlaceholders = [crashlyticsEnabled: false, analyticsEnabled: false]
            manifestPlaceholders = [analyticsEnabled: false]
        release {
            manifestPlaceholders = [analyticsEnabled: true]
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

Edit AndroidManifest.xml.

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <application ...>
            android:value="${analyticsEnabled}" />



Firebase Analytics Report

To retrieve the Analytics report, goto Firebase Console, select project, click Analytics -> Dashboard from the left panel.

Active Users are recorded by default.

Firebase Analytics Dashboard

Activity/Screen engagement are recorded by default.

Firebase Analytics Activity

Basic Events are recorded by default.

Firebase Analytics Events


This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.