• /
  • Log in
  • Free account

setUserId (iOS SDK API)

Syntax

setUserId:(NSString*)userId;
NewRelic.setUserId:(NSString*)userId;

Set a custom user identifier value to associate user sessions with analytics events and attributes.

Requirements

Compatible with version 5.9.0 or higher.

Description

This method sets a custom user identifier value to associate mobile user sessions with NRDB events. This method can be called anytime after the New Relic iOS agent starts.

A user identifier is useful for several reasons. Using the Crash analysis UI, you can:

  • Find crashes specific to a user. Focusing on one particular crash for one user often is enough to quickly resolve the issue.
  • Filter all crashes to show the occurrences for a user (or group of users) for each crash type; or, filter the crash list to show those users affected by each crash type. If the user ID is represented as an email address, it's then easy to reach out and let them know when there is a solution available that addresses those crashes.

If you do not want to explicitly identify users because of privacy rules, this method is still useful when tracking user segments, such as paid vs. free end users, or registered vs. unregistered users. This allows you to filter or facet on the number and types of crashes experienced by each segment, and do outreach based on that segment.

For context on how to use this API, see the documentation about sending custom attributes and events for:

Parameters

Parameter

Description

$userId

string

Required. Sets user ID.

Return values

Returns true if it succeeds, or false if it doesn't.

Examples

Objective-C

Method:

+ (BOOL) setUserId:(NSString*)userId;

Example:

BOOL userIdWasSet = [NewRelic setUserId:@"SampleUserName"];

Swift

Method:

NewRelic.setUserId(userId: String!) -> Bool

Example:

let userIdWasSet = NewRelic.setUserId("SampleUserName")
Create issueEdit page
Copyright © 2022 New Relic Inc.