Page updated Jan 19, 2024

Identify user

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

You can get the current user's ID from the Amplify Auth category as shown per the Auth category documentation. Be sure to have it ready before you set it as shown below (Check out the Authentication Getting Started guide for detailed explanation).

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

Breaking changes from v0 to v1:

The Analytics- prefix of the original AnalyticsUserProfile and AnalyticsUserProfileLocation classes is removed. Furthermore, AnalyticsProperties is renamed to CustomProperties.

1Future<void> addAnalyticsWithLocation({
2 required String userId,
3 required String name,
4 required String email,
5 required String phoneNumber,
6 required int age,
7}) async {
8 final userProfile = UserProfile(
9 name: name,
10 email: email,
11 location: const UserProfileLocation(
12 latitude: 47.606209,
13 longitude: -122.332069,
14 postalCode: '98122',
15 city: 'Seattle',
16 region: 'WA',
17 country: 'USA',
18 ),
19 customProperties: CustomProperties()
20 ..addStringProperty('phoneNumber', phoneNumber)
21 ..addIntProperty('age', age),
22 );
23
24 await Amplify.Analytics.identifyUser(
25 userId: userId,
26 userProfile: userProfile,
27 );
28}

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