Event Tracking

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

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 Type Required Description
Category String Yes The event category
Action String Yes The event action
Label String No The event label
Value Long No The event value

Implementation

To send an event to Google Analytics, use HitBuilders.EventBuilder and send the hit, as shown in this example:

// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
// Build and send an Event.
t.send(new HitBuilders.EventBuilder()
    .setCategory(getString(categoryId))
    .setAction(getString(actionId))
    .setLabel(getString(labelId))
    .build());

See Advanced Configuration for details on the getTracker method.

Non-interaction Events

In some cases you might want to send an event as a non-interaction event. To do this, pass true to setNonInteraction:

t.send(new HitBuilders.EventBuilder()
    .setCategory(getString(categoryId))
    .setAction(getString(actionId))
    .setNonInteraction(true)
    .build());

For more information on non-interaction hits and when to use them, read about non-interaction events in the Analytics Help Center.