Syntax
Java
NewRelic.setUserId(string $userId)
Kotlin
NewRelic.setUserId(userId: String?)
Description
Set a custom user identifier value to associate user sessions with analytics events and attributes.
This method sets a custom user identifier value to associate all events from a mobile user's session with a specific user ID. This method can be called anytime after the New Relic Android 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 is often enough to quickly resolve the issue.
Filter all crashes to show the occurrences for a user (or group of users) for each crash type; inversely, 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 more context on how to use this API, see Send custom attributes and events.
Important
The following enhancements were added in Android agent v7.4.0:
- When
setUserId(value: string|null)
is called, ifuserID
was previously null and the new value is not null, the current session continues and a newuserID
will be set. - When
setUserId(value: string|null)
is called, ifuserID
was previously not null and the newuserID
is different (includingnull
), the current session will be ended and a harvest will be performed. A new session will be created with the newuserID
.
Parameters
Parameter
Type
Description
$userID
string
Required. Sets the user ID.
Return values
Returns
true
if it succeeds, orfalse
if it doesn't.Example
Here's an example to set a user identifier to associate user session with events and attributes:
Java
- When
boolean userIdWasSet = NewRelic.setUserId("SampleUserName");
Kotlin
val userIdWasSet = NewRelic.setUserId("SampleUserName")
Syntax
Objective-c
+ (BOOL) setUserId:(NSString*)userId;
Swift
NewRelic.setUserId(userId: String!) -> Bool
Description
Set a custom user identifier value to associate user sessions with analytics events and attributes.
This method sets a custom user identifier value to associate all events from a mobile user's session with a specific user ID. 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.
Important
The following enhancements were added in iOS agent v7.5.0:
When
setUserId(value: string|null)
is called, ifuserId
was previously null and new value is not null, the current session continues and a newuserId
will be set.When
setUserId(value: string|null)
is called, ifuserId
was previously not null and newuserId
is different (includingnull
), the current session will be ended and a harvest will be performed. A new session will be created with the newuserId
.
Parameters
Parameter
Type
Description
userID
NSString
Required. The user ID to be associated with the current session.
Return values
Returns
true
if it succeeds, orfalse
if it doesn't.Example
Objective-C
BOOL userIdWasSet = [NewRelic setUserId:@"SampleUserName"];
Swift
let userIdWasSet = NewRelic.setUserId("SampleUserName")
Syntax
setUserId(options: { userId: string; }) => void
Description
Set a custom user identifier value to associate user sessions with analytics events and attributes.
Parameters
Parameter | Type | Description |
---|---|---|
|
| Required. An object that contains the user ID. |
|
| Required. The user ID to be associated with the current session. |
Example
NewRelicCapacitorPlugin.setUserId({ userId: "CapacitorUserId" });
Syntax
setUserId(userId: string): void;
Description
Set a custom user identifier value to associate user sessions with analytics events and attributes.
Parameters
Parameter | Type | Description |
---|---|---|
|
| Required. The user ID to be associated with the current session. |
Example
NewRelic.setUserId("CORDOVA12934");
Syntax
SetUserId(string userId): bool;
Description
Set a custom user identifier value to associate user sessions with analytics events and attributes.
Parameters
Parameter | Type | Description |
---|---|---|
|
| Required. The user ID to be associated with the current session. |
Example
CrossNewRelic.Current.SetUserId("User123");
Syntax
setUserId(String userId): void;
Description
Set a custom user identifier value to associate user sessions with analytics events and attributes.
Parameters
Parameter | Type | Description |
---|---|---|
|
| Required. The user ID to be associated with the current session. |
Example
NewrelicMobile.instance.setUserId("RN12934");
Syntax
setUserId(userId: string): void;
Description
Set a custom user identifier value to associate user sessions with analytics events and attributes.
Parameters
Parameter | Type | Description |
---|---|---|
|
| Required. The user ID to be associated with the current session. |
Example
NewRelic.setUserId("RN12934");
Syntax
SetUserId(string userId): bool;
Description
Set a custom user identifier value to associate user sessions with analytics events and attributes.
Parameters
Parameter | Type | Description |
---|---|---|
|
| Required. The user ID to be associated with the current session. |
Example
NewRelicAgent.SetUserId("User123");
Syntax
setUserId(FString userId): void;
Description
Set a custom user identifier value to associate user sessions with analytics events and attributes.
Parameters
Parameter | Type | Description |
---|---|---|
|
| Required. The user ID to be associated with the current session. |
Example
#include "NewRelicBPLibrary.h"
UNewRelicBPLibrary::setUserId("Unreal12934");
Syntax
SetUserId(string userId): bool;
Description
Set a custom user identifier value to associate user sessions with analytics events and attributes.
Parameters
Parameter | Type | Description |
---|---|---|
|
| Required. The user ID to be associated with the current session. |
Example
CrossNewRelicClient.Current.SetUserId("User123");