Last updated on August 22nd, 2017 at 01:12 pm

We know how much is Google analytics is important for our website to track users and session and lots of other things. Integration of Google analytics in a website is very easy you simply login to Google analytics and get analytics code and paste in your website page. Now in this post I like to explain you how to integrate Google analytics in your Android application. When you integrate analytics in your application you get various information like No. of users are active in your application, Location of users, Version which are they using and also some other information.

Integrating Google Analytics in Android Application

Step 1. Go to Firebase console and create a new project.

Step 2. Create new project name your project and select country and click on create the project.

Setup Firebase account

Step 3. Now click on Add Firebase to your Android app and name your application package name and your system SHA1 here 

Create config file android firebase

Step 4.  Now once you complete above step google-services.json is automatically downloaded on your browser if not you can download on link

Get Google service.json in firebase

Setup Google Analytics in App

Step 1. Now you need to move downloaded google-service.json file in your application Plz paste into specific location please follow bellow image

Add google-service.json file in android application

Step 2. Now open your Project Gradle and add google service library in it

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
    dependencies {
        classpath ''
        classpath ''

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

allprojects {
    repositories {

task clean(type: Delete) {
    delete rootProject.buildDir

Step 3. Now open your Application gradle and Google analytics library in it apply plugin as shown bellow.

apply plugin: ''

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.offloo"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 3
        versionName "1.2"
        testInstrumentationRunner ""
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
repositories {
    mavenCentral() // jcenter() works as well because it pulls from Maven Central
    maven {
        url ""
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('', {
        exclude group: '', module: 'support-annotations'
    compile ''
    compile 'com.instamojo:android-sdk:+'
    compile ''
    compile ''
    compile ''
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile ''
    testCompile 'junit:junit:4.12'
    compile ''
    compile ''

apply plugin: ''

Step 4. Now create Application class which extends Application in this class we initialize GoogleAnaytics as shown bellow.

package com.offloo;



public class App extends Application {

    private static GoogleAnalytics sAnalytics;
    private static Tracker sTracker;

    public void onCreate() {

        sAnalytics = GoogleAnalytics.getInstance(this);


     * Gets the default {@link Tracker} for this {@link Application}.
     * @return tracker
    synchronized public Tracker getDefaultTracker() {
        // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
        if (sTracker == null) {
            sTracker = sAnalytics.newTracker(R.xml.global_tracker);

        return sTracker;

Step 5. Now you need to call this in your manifest.xml file as shown bellow


/*  Your code */

Step 6. You can call analytic inside your activity using bellow code

// Analytics
App application = (App) getApplication();
Tracker mTracker = application.getDefaultTracker();

That’s all from mobile application part.

Enable mobile analytics reporting on Google Analytics

Step 1. Login to your google analytics.

Step 2. Click on Admin button at bottom of page

Link firebase application in google analytics

Step 3. After click on admin go to property and add new property 

Add firebase application in google analytics

Step 4. You need to select Mobile App and Firebase App and select your application

Select firebase application in google analytics

And save now you can view your analytics in firebase to view analytics you need to select your application

View mobile application analytics

Now go to Streamview menu and click on it now you check active users as shown bellow

View current active user of android application on google analytics

That’s all if you follow all steps I am sure you get your users info on google analytics.

I am already using above code in one of my e-commerce application.

Hope this blog help you. Please like and share my blog if its help you :).