Page updated Jan 16, 2024

Set up Amplify Analytics

The Analytics category enables you to collect analytics data for your App. The Analytics category comes with built-in support for Amazon Pinpoint and Amazon Kinesis (Kinesis support is currently only available in the Amplify JavaScript library). The Analytics category uses Amazon Cognito Identity pools to identify users in your App. Cognito allows you to receive data from authenticated, and unauthenticated users in your App.


To setup and configure your application with Amplify Analytics and record an analytics event.


Set up Analytics backend

Run the following command in your project's root folder. The CLI will prompt configuration options for the Analytics category such as Amazon Pinpoint resource name and analytics event settings.

The Analytics category utilizes the Authentication category behind the scenes to authorize your app to send analytics events.

1amplify add analytics
1? Select an Analytics provider (Use arrow keys)
2 `Amazon Pinpoint`
3? Provide your pinpoint resource name:
4 `yourPinpointResourceName`
5? Apps need authorization to send analytics events. Do you want to allow guests and unauthenticated users to send analytics events? (we recommend you allow this when getting started)
6 `Yes`

To deploy your backend, run:

1amplify push

A configuration file called amplifyconfiguration.json will be copied to your configured source directory, for example ./src. The CLI will also print the URL for Amazon Pinpoint console to track your app events.

Install Amplify Libraries

To install the Amplify library to use the analytics features, run the following command in your project’s root folder:

1npm install aws-amplify

Initialize Amplify Analytics

Import and load the configuration file in your app. It's recommended you add the Amplify configuration step to your app's root entry point. For example index.js in React or main.ts in Angular.

1import { record } from 'aws-amplify/analytics';
2import amplifyconfig from './amplifyconfiguration.json';

Make sure you call Amplify.configure as early as possible in your application’s life-cycle. A missing configuration or NoCredentials error is thrown if Amplify.configure has not been called before other Amplify JavaScript APIs. Review the Library Not Configured Troubleshooting guide for possible causes of this issue.

User session data is automatically collected unless you disabled analytics. To see the results visit the Amazon Pinpoint console.

View Analytics console

If you have not saved the link from before, you can still reach it from the terminal. Run the following command for opening the console.

1amplify console analytics

Next Steps:

Congratulations! Now that you have Analytics' backend provisioned and Analytics library installed. Check out the following links to see Amplify Analytics use cases: