RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Getting Started with Google Analytics on Android

The Google Analytics SDK for Android allows you to track user activity and generate useful statistics about your Android apps. Learn how to set up and use this SDK.


The Google Analytics SDK is an SDK that you can use with your existing Android applications. The Google Analytics SDK project is hosted at the Google Code site. It's an active, ongoing project so check back for updates regularly; this tutorial was written using Version 1.2. The Google Analytics SDK for Android can be used to track and collect many different types of information about your users and applications, including:

  • Track page views
  • Track specific events
  • Use custom variables to branch behavior (e.g. find out which work flow works better)
  • Track ecommerce events
  • Track Android Market referrals (Android 1.6+)

Keep in mind that you will be collecting what should be considered private data from individual users. Your application should make it clear that statistics collection is occurring within the application, either as part of your application's terms of service, or by other obvious means.

Setting Up Google Analytics on Android

To enable Google Analytics within your application requires a number of steps. You will need to:

  1. Be developing an existing Android application. Identify the types of statistics you want to gather and determine the appropriate code points to drop the statistics gathering code into.
  2. Download the Google Analytics SDK for Android zip file and extract it.
  3. Create and configure a Google Analytics developer account to use for collecting statistics.
  4. Integrate the SDK into your application project in Eclipse.
  5. Start using the SDK, adding statistics-gathering hooks in the appropriate places.
  6. View and interpret the collected data on the online Google Analytics dashboard.

Now let's look at these steps in more detail. We assume you have an existing application that you wish to integrate Google Analytics support into. However, we have also provided a very simple sample project to illustrate some of the types of statistics that can be easily generated by an Android application. The sample code that accompanies this tutorial is available online in open source form. The code listings you find here are part of this sample project, called ClickTracker.

Download the Google Analytics SDK and Create an Account

The first thing you need to do to get started is download the Google Analytics SDK for Android zip file. Note that by downloading and using the SDK, you are agreeing to additional terms of service. Extract the zip. Inside you will find a Readme, the SDK jar file, and a simple sample project that you can use if you need more help. Create a /libs directory within your Android project and save the libGoogleAnalytics.jar file within that directory.

Next, you need to create a developer account to send your application statistics to at google.com/analytics. The setup is primarily targeted at website statistics tracking, but mobile developers use the same workflow so don't get confused and think you're in the wrong place.

This account will be tied to an underlying Google Account (Gmail, etc.). It's recommended that you create your Google Analytics account with a generic Google Account, as opposed to an individual's account. The accounts are free to start and this saves your company the hassle of tracking down some errant individual who set up the account in their name and went off on vacation.

As part of the account creation, you'll be asked to log in with your Google account. Then you'll be prompted to enter some information. When you are prompted to enter a website for tracking purposes, choose a fake name (ideally including the name of your app and company domain, like clicktracker.mamlambo.com). You will also need to set the territory and time zone you want to normalize statistics to. Next, you'll enter contact information for the account. Finally, you'll need to agree to the terms of service.

The resulting account creation generates a block of JavaScript for dropping into your "website" for tracking. For mobile developers, you're really only interested in the unique Web Property or UA number associated with your account. This number is located in the JavaScript and starts with "UA-" followed by some numbers. Store this information somewhere -- you will need to use this number within your application to send statistics to the proper Google Analytics account.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date