Analytics lets you know how the user interacts with your application and that may help you take some decisions, such as:

  • Knowing which parts of your application are used the most and focus on them.
  • Knowing which parts are less used and redesign or eliminate them.
  • Discover where there are navigation issues, access to information, etc.

So having an analytics system integrated in your application is vital to lead your Android app to success.

1. Download Google Analytics library

You first need to access to Google Developers Website, where you can download the library you need to add to your project.

2. Add Google Analytics library to your Android project

Unzip the downloaded file and add the jar to libs folder. Then include it in the build path.

3. Update the manifest

If your application does not include them yet , the following permissions are required:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

4. Update activities code

All activities must override onStart and onStop methods to enable and disable tracking respectively. A good practice is creating a base activity and making all your activities extend it. Now you only need to modify this base activity.

    protected void onStart() {

    protected void onStop() {

5. Add analytics settings to values folder

Now create a file that may be called analytics.xml. These parameters are enough to configure Google Analytics:

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

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

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

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

There are some more settings that you can be seen at the documentation.

6. Create an account on Google Analytics

As you see, you need a tracking id for the first configuration parameter. You need to have an account at Google Analytics

Create a new account, and indicate that type is Application. Simply fill out another few details and get the tracking code. Include it in the configuration xml .

7. Link your Google Analytics account with Google Play Developer Console

A new feature that was recently published allows linking these two accounts to increase the potential of both by working together. All you have to do is going to Administration/Setup and enable Link Google Play applications.

From this moment, you can get much more information about how users make use of your application. Use it wisely.


What we configured till now will help you find out the number of visits (new and recurrent), location and some basic information about your browsing, basically activities access, among others.

But you still can get much more out of it. Next tutorial will explain how to use events and record visits on views (such as fragments), what will increase the potential of this tool exponentially .

Author: Antonio Leiva

I’m in love with Kotlin. I’ve been learning about it for a couple of years, applying it to Android and digesting all this knowledge so that you can learn it with no effort.