Click here to see your recently viewed pages and most viewed pages.
Hide

User ID - iOS SDK

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

  1. Overview
  2. Before you Begin
  3. Implementation
More

Overview

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. Learn more about the benefits of using User ID.

This developer guide will show you how to send User IDs to Google Analytics using the userId field and the Google Analytics SDK for iOS v3.x.

Before you Begin

Before beginning an implementation, developers should do the following:

Implementation

When a user is known to your iOS 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 using the 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 represents a generic User object returned by an authentication system on sign in.
 */
- void signInWithUser:(User *)user {

  id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

  // 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.
  [tracker set:@"&uid"
         value:user.id];

  // This hit will be sent with the User ID value and be visible in User-ID-enabled views (profiles).
  [tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"UX"            // Event category (required)
                                                        action:@"User Sign In"  // Event action (required)
                                                         label:nil              // Event label
                                                         value:nil] build]];    // Event value
}