Page updated Nov 9, 2023

Identify user

Amplify Flutter v0 is now in Maintenance Mode until July 19th, 2024. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v0.

Please use the latest version (v1) of Amplify Flutter to get started.

If you are currently using v0, follow these instructions to upgrade to v1.

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 AnalyticsUserProfileLocation.

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 location = AnalyticsUserProfileLocation()
9 ..latitude = 47.606209
10 ..longitude = -122.332069
11 ..postalCode = '98122'
12 ..city = 'Seattle'
13 ..region = 'WA'
14 ..country = 'USA';
15
16 final properties = AnalyticsProperties()
17 ..addStringProperty('phoneNumber', phoneNumber)
18 ..addIntProperty('age', age);
19
20 final userProfile = AnalyticsUserProfile()
21 ..name = name
22 ..email = email
23 ..location = location
24 ..properties = properties;
25
26 await Amplify.Analytics.identifyUser(
27 userId: userId,
28 userProfile: userProfile,
29 );
30}