User ID - Android SDK v4

This developer guides demonstrates how to implement User ID using the Google Analytics SDK for Android v4.x.


The User ID feature enables the measurement of user activities that span across devices in Google Analytics, such as attributing an interaction with a marketing campaign on one mobile device to a conversion that occurs on another mobile device or in the browser.

When User IDs are sent with Google Analytics hits using the userId field, your reports will reflect a more accurate count of unique users and offer new cross-device reporting options.

This developer guide will show you how to send user IDs to Google Analytics using the userId field and the Google Analytics SDK for Android v4.x.

Before you Begin

Before beginning your implementation, developers should do the following:


When a user is known to your Android application, you should send an ID representing that user with all of your Google Analytics hits, such as pageviews, events, ecommerce transactions, etc., using the userId field.

To send the user ID, set the userId field on the tracker using Measurement Protocol ampersand syntax and the &uid parameter name, as in this example:

 * An example method called when a user signs in to an authentication system.
 * @param User user represents a generic User object returned by an authentication system on sign in.
public void onUserSignIn(User user) {

  // Be careful when creating new trackers -- it is possible to create multiple trackers for the
  // same tracking Id.
  Tracker t = GoogleAnalytics.getInstance(context).newTracker("UA-XXXX-Y");

  // You only need to set User ID on a tracker once. By setting it on the tracker, the ID will be
  // sent with all subsequent hits.
  t.set("&uid", user.getId());

  // This hit will be sent with the User ID value and be visible in User-ID-enabled views (profiles).
  t.send(new HitBuilders.EventBuilder().setCategory("UX").setAction("User Sign In").build());