Google Analytics

Event Tracking - Android SDK v4

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

  1. Overview
  2. Implementation

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 EventBuilder and send the hit, as 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.

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.