@aws-amplify/analytics
Version:
Analytics category of aws-amplify
74 lines (72 loc) • 2.52 kB
JavaScript
;
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.identifyUser = void 0;
const utils_1 = require("@aws-amplify/core/internals/utils");
const pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
const utils_2 = require("../../../utils");
const utils_3 = require("../utils");
/**
* Sends information about a user to Pinpoint. Sending user information allows you to associate a user to their user
* profile and activities or actions in your application. Activity can be tracked across devices & platforms by using
* the same `userId`.
*
* @param {IdentifyUserInput} params The input object used to construct requests sent to Pinpoint's UpdateEndpoint
* API.
*
* @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
* @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library
* configuration is incorrect.
*
* @returns A promise that will resolve when the operation is complete.
*
* @example
* ```ts
* // Identify a user with Pinpoint
* await identifyUser({
* userId,
* userProfile: {
* email: 'userEmail@example.com'
* customProperties: {
* phoneNumber: ['555-555-5555'],
* },
* }
* });
* ```
*
* @example
* ```ts
* // Identify a user with Pinpoint with some additional demographics
* await identifyUser({
* userId,
* userProfile: {
* email: 'userEmail@example.com'
* customProperties: {
* phoneNumber: ['555-555-5555'],
* },
* demographic: {
* platform: 'ios',
* timezone: 'America/Los_Angeles'
* }
* }
* });
*/
const identifyUser = async ({ userId, userProfile, options, }) => {
const { credentials, identityId } = await (0, utils_3.resolveCredentials)();
const { appId, region } = (0, utils_3.resolveConfig)();
const { userAttributes } = options ?? {};
await (0, pinpoint_1.updateEndpoint)({
appId,
category: 'Analytics',
credentials,
identityId,
region,
userAttributes,
userId,
userProfile,
userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.IdentifyUser),
});
};
exports.identifyUser = identifyUser;
//# sourceMappingURL=identifyUser.js.map