This document describes a legacy version of the Android SDK. If your new to Analyitcs, use the latest SDK. Learn more

Event Tracking - Android SDK

Stay organized with collections Save and categorize content based on your preferences.

This developer guide describes how to measure events in your app using the Google Analytics SDK for Android v3.

Overview

Events are a useful way to collect data about a user's interaction with interactive components of your app, like button presses or the use of a particular item in a game.

An event consists of four fields that you can use to describe a user's interaction with your app content:

Field Name Tracker Field Type Required Description
Category Fields.EVENT_CATEGORY String Yes The event category
Action Fields.EVENT_ACTION String Yes The event action
Label Fields.EVENT_LABEL String No The event label
Value Fields.EVENT_VALUE Long No The event value

Implementation

To send an event to Google Analytics, use MapBuilder.createEvent() and send the hit, as in this example:

@Override
public void onClick(View v) {
  // May return null if a EasyTracker has not yet been initialized with a
  // property ID.
  EasyTracker easyTracker = EasyTracker.getInstance(this);

  // MapBuilder.createEvent().build() returns a Map of event fields and values
  // that are set and sent with the hit.
  easyTracker.send(MapBuilder
      .createEvent("ui_action",     // Event category (required)
                   "button_press",  // Event action (required)
                   "play_button",   // Event label
                   null)            // Event value
      .build()
  );
}