Page updated Nov 8, 2023

Identify user to Amazon Pinpoint

This call identifies the current user (which could be unauthenticated or authenticated) to Amazon Pinpoint. The user ID can be any string which identifies the user in the context of your application.

Get the user ID from Amplify Auth

If the user is signed in through Amplify Auth signIn, then you can retrieve the current user's ID as shown below:

1import { getCurrentUser, GetCurrentUserOutput } from 'aws-amplify/auth';
2
3const { userId }: GetCurrentUserOutput = await getCurrentUser();
1import { getCurrentUser } from 'aws-amplify/auth';
2
3const { userId } = await getCurrentUser();

Identify the user to Amazon Pinpoint

Once you have a string that identifies the current user (either from the Auth category as shown above or through your own application logic), you can identify the user to Amazon Pinpoint with the following:

1import {
2 identifyUser,
3 IdentifyUserInput
4} from 'aws-amplify/push-notifications';
5
6const identifyUserInput: IdentifyUserInput = {
7 userId: '', // E.g. user-id
8 userProfile: {
9 email: '', // E.g. example@service.com
10 name: '', // E.g. name-of-the-user
11 plan: '' // E.g. plan-they-subscribe-to
12 customProperties: {
13 // E.g. hobbies: ['cooking', 'knitting'],
14 },
15 demographic: {
16 appVersion: '',
17 locale: '', // E.g. en_US
18 make: '', // E.g. Apple
19 model: '', // E.g. iPhone
20 modelVersion: '', // E.g. 13
21 platform: '', // E.g. iOS
22 platformVersion: '', // E.g. 15
23 timezone: '' // E.g. Americas/Los_Angeles
24 },
25 location: {
26 city: '', // E.g. Seattle
27 country: '', // E.g. US,
28 postalCode: '', // E.g. 98121
29 region: '', // E.g. WA
30 latitude: 0.0,
31 longitude: 0.0
32 },
33 metrics: {
34 // E.g. logins: 157
35 },
36 },
37};
38
39await identifyUser(identifyUserInput);
1import { identifyUser } from 'aws-amplify/push-notifications';
2
3const identifyUserInput = {
4 userId: '', // E.g. user-id
5 userProfile: {
6 email: '', // E.g. example@service.com
7 name: '', // E.g. name-of-the-user
8 plan: '' // E.g. plan-they-subscribe-to
9 customProperties: {
10 // E.g. hobbies: ['cooking', 'knitting'],
11 },
12 demographic: {
13 appVersion: '',
14 locale: '', // E.g. en_US
15 make: '', // E.g. Apple
16 model: '', // E.g. iPhone
17 modelVersion: '', // E.g. 13
18 platform: '', // E.g. iOS
19 platformVersion: '', // E.g. 15
20 timezone: '' // E.g. Americas/Los_Angeles
21 },
22 location: {
23 city: '', // E.g. Seattle
24 country: '', // E.g. US,
25 postalCode: '', // E.g. 98121
26 region: '', // E.g. WA
27 latitude: 0.0,
28 longitude: 0.0
29 },
30 metrics: {
31 // E.g. logins: 157
32 },
33 },
34};
35
36await identifyUser(identifyUserInput);

When using identifyUser with Amazon Pinpoint, in addition to the other user info properties you can configure the address, optOut and userAttributes properties under options.

1import {
2 identifyUser,
3 IdentifyUserInput
4} from 'aws-amplify/push-notifications';
5
6const identifyUserInput: IdentifyUserInput = {
7 userId: '', // E.g. user-id
8 options: {
9 address: '' // E.g. A device token or email address
10 optOut: '' // Either ALL or NONE
11 userAttributes: {
12 // E.g. interests: ['soccer', 'shoes'],
13 }
14 }
15};
16
17await identifyUser(identifyUserInput);
1import { identifyUser } from 'aws-amplify/push-notifications';
2
3const identifyUserInput = {
4 userId: '', // E.g. user-id
5 options: {
6 address: '' // E.g. A device token or email address
7 optOut: '' // Either ALL or NONE
8 userAttributes: {
9 // E.g. interests: ['soccer', 'shoes'],
10 }
11 },
12
13};
14
15await identifyUser(identifyUserInput);