Identify user
This call sends information about the current user (which could be unauthenticated or authenticated) to Amazon Pinpoint.
You can provide name
, email
and plan
, as well as location information with AnalyticsUserProfile.Location
. You can also send additional custom attributes using AnalyticsProperties
.
If the user is signed in through Amplify.Auth.signIn, then you can retrieve the current user's ID as shown below:
1let user = try await Amplify.Auth.getCurrentUser()2
3let location = AnalyticsUserProfile.Location(4 latitude: 47.606209,5 longitude: -122.332069,6 postalCode: "98122",7 city: "Seattle",8 region: "WA",9 country: "USA"10)11
12let properties: AnalyticsProperties = [13 "phoneNumber": "+11234567890",14 "age": 2515]16
17let userProfile = AnalyticsUserProfile(18 name: "username",19 email: "name@example.com",20 plan: "plan",21 location: location,22 properties: properties23)24
25Amplify.Analytics.identifyUser(26 userId: user.userId,27 userProfile: userProfile28)
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