Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Feb 21, 2024

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:

import { getCurrentUser, GetCurrentUserOutput } from 'aws-amplify/auth';
const { userId }: GetCurrentUserOutput = await getCurrentUser();
import { getCurrentUser } from 'aws-amplify/auth';
const { 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:

import {
identifyUser,
IdentifyUserInput
} from 'aws-amplify/push-notifications';
const identifyUserInput: IdentifyUserInput = {
userId: '', // E.g. user-id
userProfile: {
email: '', // E.g. example@service.com
name: '', // E.g. name-of-the-user
plan: '' // E.g. plan-they-subscribe-to
customProperties: {
// E.g. hobbies: ['cooking', 'knitting'],
},
demographic: {
appVersion: '',
locale: '', // E.g. en_US
make: '', // E.g. Apple
model: '', // E.g. iPhone
modelVersion: '', // E.g. 13
platform: '', // E.g. iOS
platformVersion: '', // E.g. 15
timezone: '' // E.g. Americas/Los_Angeles
},
location: {
city: '', // E.g. Seattle
country: '', // E.g. US,
postalCode: '', // E.g. 98121
region: '', // E.g. WA
latitude: 0.0,
longitude: 0.0
},
metrics: {
// E.g. logins: 157
},
},
};
await identifyUser(identifyUserInput);
import { identifyUser } from 'aws-amplify/push-notifications';
const identifyUserInput = {
userId: '', // E.g. user-id
userProfile: {
email: '', // E.g. example@service.com
name: '', // E.g. name-of-the-user
plan: '' // E.g. plan-they-subscribe-to
customProperties: {
// E.g. hobbies: ['cooking', 'knitting'],
},
demographic: {
appVersion: '',
locale: '', // E.g. en_US
make: '', // E.g. Apple
model: '', // E.g. iPhone
modelVersion: '', // E.g. 13
platform: '', // E.g. iOS
platformVersion: '', // E.g. 15
timezone: '' // E.g. Americas/Los_Angeles
},
location: {
city: '', // E.g. Seattle
country: '', // E.g. US,
postalCode: '', // E.g. 98121
region: '', // E.g. WA
latitude: 0.0,
longitude: 0.0
},
metrics: {
// E.g. logins: 157
},
},
};
await 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.

import {
identifyUser,
IdentifyUserInput
} from 'aws-amplify/push-notifications';
const identifyUserInput: IdentifyUserInput = {
userId: '', // E.g. user-id
options: {
address: '' // E.g. A device token or email address
optOut: '' // Either ALL or NONE
userAttributes: {
// E.g. interests: ['soccer', 'shoes'],
}
}
};
await identifyUser(identifyUserInput);
import { identifyUser } from 'aws-amplify/push-notifications';
const identifyUserInput = {
userId: '', // E.g. user-id
options: {
address: '' // E.g. A device token or email address
optOut: '' // Either ALL or NONE
userAttributes: {
// E.g. interests: ['soccer', 'shoes'],
}
},
};
await identifyUser(identifyUserInput);