Page updated Jan 19, 2024

Identify user

This call sends information that you have specified about the user to Amazon Pinpoint. This could be for an unauthenticated or an authenticated user.

In addition, customProperties and userAttributes can also be provided when invoking identifyUser. The Amazon Pinpoint console makes that data available as part of the criteria for segment creation. Attributes passed in via customProperties will appear under Custom Endpoint Attributes, while userAttributes will appear under Custom User Attributes. See the Pinpoint documentation for more information on segment creation.

You can get the current user's ID from the Amplify Auth category as shown below. Be sure you have it added and setup per the Auth category documentation.

If you have asked for location access and received permission, you can also provide that in UserProfile.Location.

1UserProfile.Location location = UserProfile.Location.builder()
2 .latitude(47.606209)
3 .longitude(-122.332069)
4 .postalCode("98122")
5 .city("Seattle")
6 .region("WA")
7 .country("USA")
8 .build();
9
10AnalyticsProperties customProperties = AnalyticsProperties.builder()
11 .add("property1", "Property value")
12 .build();
13
14AnalyticsProperties userAttributes = AnalyticsProperties.builder()
15 .add("someUserAttribute", "User attribute value")
16 .build();
17
18AWSPinpointUserProfile profile = AWSPinpointUserProfile.builder()
19 .name("test-user")
20 .email("user@test.com")
21 .plan("test-plan")
22 .location(location)
23 .customProperties(customProperties)
24 .userAttributes(userAttributes)
25 .build();
26
27Amplify.Auth.getCurrentUser(authUser -> {
28 String userId = authUser.getUserId();
29 Amplify.Analytics.identifyUser(userId, profile);
30}, exception -> {
31 Log.e("MyAmplifyApp", "Error getting current user", exception);
32});
1val location = UserProfile.Location.builder()
2 .latitude(47.606209)
3 .longitude(-122.332069)
4 .postalCode("98122")
5 .city("Seattle")
6 .region("WA")
7 .country("USA")
8 .build();
9
10val customProperties = AnalyticsProperties.builder()
11 .add("property1", "Property value")
12 .build();
13
14val userAttributes = AnalyticsProperties.builder()
15 .add("someUserAttribute", "User attribute value")
16 .build();
17
18val profile = AWSPinpointUserProfile.builder()
19 .name("test-user")
20 .email("user@test.com")
21 .plan("test-plan")
22 .location(location)
23 .customProperties(customProperties)
24 .userAttributes(userAttributes)
25 .build();
26
27Amplify.Auth.getCurrentUser({ authUser ->
28 Amplify.Analytics.identifyUser(authUser.userId, profile);
29}, { exception ->
30 Log.e("MyAmplifyApp", "Error getting current user", exception)
31})
1UserProfile.Location location = UserProfile.Location.builder()
2 .latitude(47.606209)
3 .longitude(-122.332069)
4 .postalCode("98122")
5 .city("Seattle")
6 .region("WA")
7 .country("USA")
8 .build();
9
10AnalyticsProperties customProperties = AnalyticsProperties.builder()
11 .add("property1", "Property value")
12 .build();
13
14AnalyticsProperties userAttributes = AnalyticsProperties.builder()
15 .add("someUserAttribute", "User attribute value")
16 .build();
17
18AWSPinpointUserProfile profile = AWSPinpointUserProfile.builder()
19 .name("test-user")
20 .email("user@test.com")
21 .plan("test-plan")
22 .location(location)
23 .customProperties(customProperties)
24 .userAttributes(userAttributes)
25 .build();
26
27RxAmplify.Auth.getCurrentUser()
28 .subscribe(
29 result -> {
30 String userId = result.getUserId();
31 RxAmplify.Analytics.identifyUser(userId, profile);
32 },
33 error -> Log.e("AuthQuickStart", error.toString())
34 );

Sending user information allows you to associate a user to their user profile and activities or actions in your app. The user's actions and attributes can also tracked across devices and platforms by using the same userId.

Some scenarios for identifying a user and their associated app activities are:

  • When a user completes app sign up
  • When a user completes sign in process
  • When a user launches your app
  • When a user modifies or updates their user profile