Intive Blog

Google Analytics on Android

Google Analytics is a platform available for developers and web site owners or applications to monitor users’ behaviors within their products.

This Google tool is key for an app to be successful, since it allows us to know what parts are mostly used, by recording what pages are being visited more often and which are not.

What do you need to use it?

  • Import the necessary libraries using Gradle.
  • You need to have a Google Analytics account with a tracker id on the following format: UA-XXXXXXXX-X.
  • Initialize the Google tracker in Application.
Why may we want to use it?

  • Screens follow-up

Ideally, when it is time to perform a screen follow-up we should declare a base fragment/activity to follow-up the methods onResume and onPause. Furthermore, it is necessary that each “screen” has an id name declared in an explicit way on the code. I mean a variable as follows.

This is for two reasons:

  1. The name we will send to Analytics will impact on the reports and if there is someone outside the development team, even someone different to the original developer who was accountable for the follow-up, he/she will find several “strange names” that might indicate not indicate what is expected.
  2. By obfuscating code with Proguard, names of classes to identify screens cannot be used.

Important:

Fragments follow-up within tabs (for instance using a ViewPager) is a particular case: we should not send a follow-up in methods OnResume and onPause of the fragment. This is because, for example, pages are preloaded before they are visible to users, since these methods are triggered before being visible. For this, a more elaborate follow-up must be carried out looking for some useful callback such as UserVisibleHint (Boolean is VisibleToUser).

  • Exceptions follow-up

Google Analytics offers a follow-up of exceptions that come up on the devices where the application is running- The snag is there is no way to pass a mapping for obfuscated code by Proguard, so in this case it is convenient to use some other service like Crashlytics to control errors.

  • Events follow-up

An event can be considered a user action on a screen (a click, a swipe, a pinch, etc.) and in some cases it is interesting to keep a record of some of them to see how users interact with the UI. This would allow us to improve the UI for users to feel more comfortable or to incentivize users to reach a particular destination (generally, a place that implies that users will make us earn money).

Basically an event consists of the following fields:

  1. Category
  2. Action
  3. Label

Sending events is very simple:

Some details to bear in mind when events are sent is that the SDK on Google Analytics for Android can limit the events, along with some hits, if a great number of delivery calls are performed in a short time.

 

Sources:

https://developers.google.com/analytics/devguides/collection/android/v4/?hl=en
https://www.udacity.com/course/google-analytics-for-android–ud876-2

Gastón Goncalves

He has been with intive – FDV since 2012. As of February 2015, he has been an Android developer. Previously he was a Drools and Java EE developer. He is currently studying I.T. engineering at Universidad de Buenos Aires (UBA). He was also a teacher at UBA, teaching Algorithms and Programming II in the Engineering department.

Add comment