Google Analytics

Google Analytics SDK for Android v3 (Beta) - Getting Started

This document describes how to get started using the Google Analytics SDK for Android v3.

  1. Before You Begin
  1. Getting Started
    1. 1. Updating AndroidManifest.xml
    2. 2. Adding EasyTracker methods
    3. 3. Creating your analytics.xml file
  1. Next steps

Before you Begin

Before implementing the SDK, make sure you have the following:

Getting Started

There are three steps to getting started with the SDK:

  1. Update AndroidManifest.xml
  2. Add EasyTracker methods
  3. Create your analytics.xml file

After completing these steps, you'll be able to measure the following with Google Analytics:

  • App installations
  • Active users and demographics
  • Screens and user engagement
  • Crashes and exceptions

1. Updating AndroidManifest.xml

Update your AndroidManifest.xmle file by adding the following permissions:

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

2. Adding EasyTracker methods

Add the send methods to the onStart() and onStop() methods of each of your Activities as in the following example:

package com.example.app;

import android.app.Activity;

import com.google.analytics.tracking.android.EasyTracker;

/**
 * An example Activity using Google Analytics and EasyTracker.
 */
public class myTrackedActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  }

  @Override
  public void onStart() {
    super.onStart();
    ... // The rest of your onStart() code.
    EasyTracker.getInstance(this).activityStart(this);  // Add this method.
  }

  @Override
  public void onStop() {
    super.onStop();
    ... // The rest of your onStop() code.
    EasyTracker.getInstance(this).activityStop(this);  // Add this method.
  }
}

3. Creating your analytics.xml file

When you use EasyTracker, global configuration settings are managed using resources defined in XML. Create a file called analytics.xml in your project's res/values directory and add the following resources:

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

<resources>
  <!--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>
</resources>

Your lint checker may warn you about the use of the figure dash ('-') in your tracking ID. You can suppress that warning by adding additional attributes to your <resources> tag:

<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="TypographyDashes">

See the analytics.xml parameters reference for the complete list of parameters you can use to configure your implementation. Depending on your applications requirements, you may wish to change the dispatch period to verify that you are properly sending hits. For example if you want to see real time data, you may want to set this to a low value such as 5s.

Congratulations! Your app is now setup to send data to Google Analytics.

Next steps

You can do much more with Google Analytics, including measuring campaigns, in-app payments and transactions, and user interaction events. See the following developer guides to learn how to add these features to your implementation:

  • Advanced Configuration – Learn more about advanced configuration options, including using multiple trackers.
  • Measuring Campaigns – Learn how to implement campaign measurement to understand which channels and campaigns are driving app installs.
  • Measuring Events – Learn how to measure user engagement with interactive content like buttons, videos, and other media using Events.
  • Measuring In-App Payments – Learn how to measure in-app payments and transactions.
  • User timings – Learn how to measure user timings in your app to measure load times, engagement with media, and more.
  • Analytics.xml parameters – See the complete list of analytics.xml configuration parameters.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.