1. Why Analytics in Mobile app ?

Analytics is one of the major parts in applications that drive revenue.  Mobile App Analytics help you set and track the goal conversions you want most: purchases, clicks, or simply time spent on your app. It is required to make business inclined towards user’s interest. For example, if you developing an application for Mobile Shopper app, it is important to track the below things.

  1. Number of users/active users from across the world
  2. Most viewed products, categories, brands, etc.
  3. Number of users placing request, etc.

The above information is required in order to improve the product and make the service is better.

2. Introduction to Google Analytics

The Google Analytics Platform lets you measure user interactions with your business across various devices and environments. The platform provides all the computing resources to collect, store, process, and report on these user-interactions.

3. Supported Features

Below are the currently supported features. Read more


  1. Google Play Integration
  2. Crash and Exception Reporting
  3. Custom Reports
  4. Event Tracking
  5. Flow Visualization
  6. Real-Time Reporting

4. How to use Google Analytics in android

This section of tutorial we will see detailed steps to install Google Analytics for your android application. Before begin with Analytics integration we need the following items

  1. Android developer SDK and required configurations. I assume you have it already, if not you can follow Android official documentation http://developer.android.com/sdk/index.html
  2. Google Analytics SDK for Android v3, with libGoogleAnalyticsServices.jar file. Copy this file in your project’s /libs directory.
  3. Codebase of an Android app that you like to implement the Google Analytics
  4. Create a Google Analytics account (Requires Gmail), and then create a new app property and view in the Analytics console.

5. Using Google Analytics Detailed Steps

Before starting with section, I assume you already have Codebase of an Android app that you like to implement the Google Analytics. But to simplify my example, I am creating an simple Android App and integrating with Google Analytics.

5.1. Creating Google Analytics Account and App Property

  1. Login to your Google Analytics Account. Then press “Admin” button on the right side of your screen.
  2. Create a new Account, if you don’t have one and then create a new property. While creating a new property choose Mobile App.
  3. After property is created, you will get the tracking Id. This tracking id will be used as configuration in android app.

5.2. Add analytics.xml configuration file

Add analytics.xml configuration file in your application values folder

<?xml version="1.0" encoding="utf-8"?>

    <!-- Replace placeholder ID with your tracking ID -->
    <string name="ga_trackingId">UA-xxxxxxxxxx</string>

    <!-- Enable automatic activity tracking -->
    <bool name="ga_autoActivityTracking">true</bool>

    <!-- Enable automatic exception tracking -->
    <bool name="ga_reportUncaughtExceptions">true</bool>    



5.3. Android Activity Layout (activity_main.xml)

For this example, I have created an sample Activity with two buttons for tracking event and exceptions.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    tools:context=".MainActivity" >

        android:text="@string/info" />

        android:text="Track Event" />

        android:text="Track Crash" />


5.4. Android Activity (MainActivity.java)

Now, you need to write the tracking code in your activity class. For that simply add the activiyStart() and activityStop() methods to the onStart() and onStop() methods of each of your Activities as in the following example. This two method enables basic activity tracking.

package com.javatechig.ganalytics;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytics.tracking.android.MapBuilder;
import com.google.analytics.tracking.android.StandardExceptionParser;

public class MainActivity extends Activity {

	private EasyTracker easyTracker = null;

	protected void onCreate(Bundle savedInstanceState) {

		easyTracker = EasyTracker.getInstance(MainActivity.this);

		findViewById(R.id.trackEvent).setOnClickListener(new OnClickListener() {

			public void onClick(View view) {
						"envet_name", "button_name/id", null).build());

		findViewById(R.id.trackCrash).setOnClickListener(new OnClickListener() {

			public void onClick(View view) {

				try {
					int a[] = new int[2];
					int num = a[4];
				} catch (ArrayIndexOutOfBoundsException e) {
									new StandardExceptionParser(MainActivity.this, null)
											.getDescription(Thread.currentThread().getName(), e), false).build());


	public void onStart() {

	public void onStop() {

	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;


In this above activity code sample, we are tracking event an crashes on two button clicks. Just for demonstation purpose I am creating sample exception and tracking it.

6. Google Analytics Output

Google Analytics Report

7. Download Complete Example


This article is about: 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 (goo.gl/qUZ0XV3), DZone MVB and founder of stacktips.com.


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

    Hey I didn’t find your code work. I didn’t found any user in the console as well. Can you please tell me when you are using tracking_id? I don’t think without it the analytic works.

    Poor tutorial I didn’t find any helpful thing in it.

  • باسل

    Is the any tutorial (uniform way) to add it on IBM worklight apps

  • Rajiv

    Is there any possibility to implement the same tracking to Android APK which is not Placed in google play store..? If yes please guide how to…

    Thanks in Advance!

  • Hasamm

    Fantastic tutorial. Thanks.

  • May Mg

    my app is not affected.

    • Can you verify wether the GA id is the right one ?

  • May Mg

    what data set in easytracker.send method.Pls tell me


    Great Tutorial ..!!! +1 For your clean steps. :) The Analytics Works well, Can you Please tell us how exactly Tracker-id works for EasyTracker.?? Where can we get detailed Info. about different properties and classes for Google Analytics. Any link for detailed study ????

    Thanks and continue your great contribution to Droid ;)

  • Ramesh

    Hi all..
    I need to know the origin of request to download my app from https://play.google.com

    like my app was advertised in so many apps, just like as ads,
    when the user click on that add and redirected to https://play.google.com and download will started.

    Now i would like get that source(app) name from where the user find my app.

  • Sravani Ch

    I have added start and stop methods to all of my activities in my application but it is tracking only one activity. why?
    easy tracker tracks only one activity per application . Any one please reply

    • Nilanchala Panigrahy

      EasyTracker should list all activities. Sometimes it may take a while. Please check back and see if you still experience the issue.

      • Sravani Ch

        Ok. I have checked multiple times if i am in one activity which is tracking it is showing Right Now value is “1” and it is showing complete class name of that activity under the “Top activity Screens” but if i stay in other activities for 15 min also its not tracking

  • Alberto

    Thanks! You literally saved my life from the disaster!!

  • Pravinsingh_Waghela

    Well I tried what you mentioned above, but I can’t see any users details on my Google Analytic Account. Am I missing anything?

    • Nilanchala Panigrahy

      are you using your correct tracking id? that matters.

      • Pravinsingh_Waghela

        Thanks mate, its now working…Thanks to you…

        • Pravinsingh_Waghela

          well Now its working. actually it reflects after some 24 hours…

  • Deepak

    great its very simple and understandable ,,,,,,,Gracias…..