After you release your app to market, it is important to study how people use your application to make informed decisions about how to improve and market your app. For this you can integrate app measurement solutions to your app.

There are many free and premium app measurement solutions out there in market. Google Analytics, Flurry, Adobe Omniture are most popular ones. Google recently added Firebase Analytics to the race. The core idea behind all of these tools are to provide insight on app usage and user engagement.

1. What is Firebase Analytics?

Firebase Analytics from Google, is a free app measurement solution using which you can understand how people use your app and track user engagement.

  • Firebase SDK for mobile platforms, automatically captures a number of events and user properties and also allows you to define your own custom events to measure the things that uniquely matter to your business.
  • It also allows you to perform custom analysis and do complex analysis by joining multiple data sources.
  • You can track how your campaigns across organic and paid channels are performing and accordingly define an effective marketing strategy.

The detailed insight of your data can be viewed in Firebase console. The dashboard provides detailed insights about your data — from summary data such as active users and demographics, to more detailed data such as identifying your most purchased items.

2. Integrating Firebase Analytics

To use Firebase Analytics to your Android project, you need Android 2.3 (Gingerbread) or newer and Google Play Services 9.4.0 or newer. In this example we use Android Studio 2.2Mximunum SDK version 17.

Now that we understand what Firebase Analytics platform can do, let us see how to use Firebase Analytics to your Android application to track application usage. Integrating with Firebase Analytics in Android involves  two steps; installing the Firebase SDK and Logging events and/or properties.

2.1. Configure the Firebase SDK

Let us begin with creating a Firebase project in the Firebase console. You will be asked to login with your Google Mail account. Once you logged in, select Add App button to create a new project in Firebase Console.

  1. Select the Android platform to continue with Android Firebase configuration.

Create new project in Firebase console- Select Platform

  1. If you have not created any app before, you will be asked to select the Project Name and Country Region. Provide the details and Continue with the configuration.
  2. Enter your Android app package name. This should be same as defined in your android AndroidMaifest.xml file.

Firebase Android Configuration

  1. You may provide the debug keystore SHA-1 certificate. However this is optional and hence you may leave it empty.
  2. Select Add App button. This will download the google-services.json configuration file for your app. Copy this file into your project’s module folder, typically inside app/ directory.
Project Structure

Screenshot depicts project structure after adding google-services.json file

  1. Now, add the required Firebase SDK dependencies to your project. Modify the project level build.gradle (<project>/build.gradle) file and add the google-services.
buildscript {
  dependencies {
    // Add this line
    classpath ''

And, add the following to app module level build.gradle file.

apply plugin: ''
android {
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    //Add this
    compile ''

// Add to the bottom of the file
apply plugin: ''

After the dependencies are added Sync your project with gradle file changes. With this we’re done with the project configuration. Once the Firebase SDK is configured properly, several events are captured automatically by Firebase. Check out the list of default events tracked by Firebase SDK.

2.2. Tracking User Events

Let us first obtain the FirebaseAnalytics singleton instance. The FirebaseAnalytics class is the heart of all firebase configuration that provides method for logging events and setting user properties. Currently it provides following methods:

getInstance(Context context)
Returns the singleton FirebaseAnalytics interface.
logEvent(String name, Bundle params)
Logs an app event.
setAnalyticsCollectionEnabled(boolean enabled)
Sets whether analytics collection is enabled for this app on this device.
setMinimumSessionDuration(long milliseconds)
Sets the minimum engagement time required before starting a session. The default value is 10000 (10 seconds).
setSessionTimeoutDuration(long milliseconds)
Sets the duration of inactivity that terminates the current session. The default value is 1800000 (30 minutes).
setUserId(String id)
Sets the user ID property.
setUserProperty(String name, String value)
Sets a user property to a given value.

You can use the above methods to configure firebase analytics tracker and track custom everts.

public class MainActivity extends AppCompatActivity {

    private FirebaseAnalytics mFirebaseAnalytics;

    protected void onCreate(Bundle savedInstanceState) {

        // Obtain the FirebaseAnalytics instance.
        mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

        Button subscribeButton = (Button) findViewById(;
        subscribeButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                String id = "1year";
                String name = "Annual membership subscription";
                bundle.putString(FirebaseAnalytics.Param.ITEM_ID, id);
                bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
                bundle.putString(FirebaseAnalytics.Param.CURRENCY, "EUR");
                bundle.putString(FirebaseAnalytics.Param.PRICE, "299.00");
                mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);


2.3. Tracking User Properties

User properties are attributes you define to describe segments of your userbase, such as language preference or geographic location. Firebase automatically logs some of the user properties; such as App version, Device model, Gender, Age, Interests, OS version and New/Established.

You can set up to 25 different Analytics User Properties in your app.

Note that, the user property names are case-sensitive and that setting two user properties whose names differ only in case results in two distinct user properties being logged.

mFirebaseAnalytics.setUserProperty("favorite_category", "Android Tutorials");

3. Download Example


This article is about: App Tracking, Firebase, Google Analytics,


A blogger, a bit of tech freak and a software developer. He is a thought leader in the fusion of design and mobile technologies. He is the author of Xamarin Mobile Application Development for Android Book (, DZone MVB and founder of


Please note: We reserve the right to delete comments that contains snarky remarks, offensive or off-topic. To know more read our comments policy.