This developer guides demonstrates how to implement User ID using the Google Analytics SDK v4 for Android.
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 guide shows how to use the
userId field and the Google
Analytics SDK for Android to send user IDs to Google Analytics.
Before you Begin
Before beginning your implementation, developers should do the following:
- Enable one of your views (profiles) for User ID (Help Center)
- Review the User ID Policy
- Learn how User ID works by reviewing the User ID Feature Reference
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
To send the user ID, set the
userId field on the tracker using
ampersand syntax and the
&uid parameter name, as in this example:
// Get tracker. Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker( TrackerName.APP_TRACKER); // 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.setClientId(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());