Page updated Jan 16, 2024

Use existing AWS resources

Set up existing analytics backend

The manual setup enables you to use your existing Amazon Pinpoint resource in your app.

1import { Amplify } from 'aws-amplify';
2
3Amplify.configure({
4 // To get the AWS Credentials, you need to configure
5 // the Auth module with your Cognito Federated Identity Pool
6 Auth: {
7 identityPoolId: 'us-east-1:xxx-xxx-xxx-xxx-xxx',
8 region: 'us-east-1'
9 },
10 Analytics: {
11 // OPTIONAL - disable Analytics if true
12 disabled: false,
13 // OPTIONAL - Allow recording session events. Default is true.
14 autoSessionRecord: true,
15
16 AWSPinpoint: {
17 // OPTIONAL - Amazon Pinpoint App Client ID
18 appId: 'XXXXXXXXXXabcdefghij1234567890ab',
19 // OPTIONAL - Amazon service region
20 region: 'XX-XXXX-X',
21 // OPTIONAL - Customized endpoint
22 endpointId: 'XXXXXXXXXXXX',
23 // OPTIONAL - Default Endpoint Information
24 endpoint: {
25 address: 'xxxxxxx', // The unique identifier for the recipient. For example, an address could be a device token, email address, or mobile phone number.
26 attributes: {
27 // Custom attributes that your app reports to Amazon Pinpoint. You can use these attributes as selection criteria when you create a segment.
28 hobbies: ['piano', 'hiking']
29 },
30 channelType: 'APNS', // The channel type. Valid values: APNS, GCM
31 demographic: {
32 appVersion: 'xxxxxxx', // The version of the application associated with the endpoint.
33 locale: 'xxxxxx', // The endpoint locale in the following format: The ISO 639-1 alpha-2 code, followed by an underscore, followed by an ISO 3166-1 alpha-2 value
34 make: 'xxxxxx', // The manufacturer of the endpoint device, such as Apple or Samsung.
35 model: 'xxxxxx', // The model name or number of the endpoint device, such as iPhone.
36 modelVersion: 'xxxxxx', // The model version of the endpoint device.
37 platform: 'xxxxxx', // The platform of the endpoint device, such as iOS or Android.
38 platformVersion: 'xxxxxx', // The platform version of the endpoint device.
39 timezone: 'xxxxxx' // The timezone of the endpoint. Specified as a tz database value, such as Americas/Los_Angeles.
40 },
41 location: {
42 city: 'xxxxxx', // The city where the endpoint is located.
43 country: 'xxxxxx', // The two-letter code for the country or region of the endpoint. Specified as an ISO 3166-1 alpha-2 code, such as "US" for the United States.
44 latitude: 0, // The latitude of the endpoint location, rounded to one decimal place.
45 longitude: 0, // The longitude of the endpoint location, rounded to one decimal place.
46 postalCode: 'xxxxxx', // The postal code or zip code of the endpoint.
47 region: 'xxxxxx' // The region of the endpoint location. For example, in the United States, this corresponds to a state.
48 },
49 metrics: {
50 // Custom metrics that your app reports to Amazon Pinpoint.
51 },
52 /** Indicates whether a user has opted out of receiving messages with one of the following values:
53 * ALL (default) - User has opted out of all messages.
54 * NONE - Users has not opted out and receives all messages.
55 */
56 optOut: 'ALL',
57 // Customized userId
58 userId: 'XXXXXXXXXXXX',
59 // User attributes
60 userAttributes: {
61 interests: ['football', 'basketball', 'AWS']
62 // ...
63 }
64 },
65
66 // Buffer settings used for reporting analytics events.
67 // OPTIONAL - The buffer size for events in number of items.
68 bufferSize: 1000,
69
70 // OPTIONAL - The interval in milliseconds to perform a buffer check and flush if necessary.
71 flushInterval: 5000, // 5s
72
73 // OPTIONAL - The number of events to be deleted from the buffer when flushed.
74 flushSize: 100,
75
76 // OPTIONAL - The limit for failed recording retries.
77 resendLimit: 5
78 }
79 }
80});

Update your IAM Policy

Amazon Pinpoint service requires an IAM policy in order to use the record API:

1{
2 "Version": "2012-10-17",
3 "Statement": [
4 {
5 "Effect": "Allow",
6 "Action": ["mobiletargeting:UpdateEndpoint", "mobiletargeting:PutEvents"],
7 "Resource": ["arn:aws:mobiletargeting:*:${accountID}:apps/${appId}*"]
8 }
9 ]
10}