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.
Goal
To setup and configure your application with Amplify Analytics and record an analytics event.
Prerequisites
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.
amplify add analytics
? Select an Analytics provider (Use arrow keys) `Amazon Pinpoint`? Provide your pinpoint resource name: `yourPinpointResourceName`? 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) `Yes`
To deploy your backend, run:
amplify 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:
npm 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, App.js (Expo) or index.js (React Native CLI).
import { record } from 'aws-amplify/analytics';import amplifyconfig from './amplifyconfiguration.json';
Amplify.configure(amplifyconfig);
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.
amplify 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:
Known Issues
When importing alternative service providers listed below, instead of the default Pinpoint provider:
- Kinesis (
aws-amplify/analytics/kinesis
) - Kinesis Data Firehose (
aws-amplify/analytics/kinesis-firehose
) - Personalize Event (
aws-amplify/analytics/personalize
)
you may encounter the following error when starting the bundler:
Error: Unable to resolve module stream from /path/to/node_modules/@aws-sdk/... This is a known issue. Please follow the steps outlined in the issue to resolve the error.