AWS Amplify Analytics module helps you quickly collect analytics for user sessions, custom attributes or metrics.
Please refer to this Guide for general setup. Here are Analytics specific setup.
import Amplify from 'aws-amplify';
Amplify.configure(
Auth: {
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab', //REQUIRED - Amazon Cognito Identity Pool ID
region: 'XX-XXXX-X', // REQUIRED - Amazon Cognito Region
userPoolId: 'XX-XXXX-X_abcd1234', //OPTIONAL - Amazon Cognito User Pool ID
userPoolWebClientId: 'XX-XXXX-X_abcd1234', //OPTIONAL - Amazon Cognito Web Client ID
},
Analytics: {
appId: 'XXXXXXXXXXabcdefghij1234567890ab', //OPTIONAL - Amazon Pinpoint App ID
region: 'XX-XXXX-X', //OPTIONAL - Amazon service region
});
In the above configuration you are required to pass in an Amazon Cognito Identity Pool ID so that the library can retrieve base credentials for a user even in an UnAuthenticated state. If you pass in properties in the Analytics section for Amazon Pinpoint the library will automatically track some base metrics for you without any effort on your part.
To create a project fully functioning with the Analytics category.
After configuration, user session metrics are automatically collected and send to Amazon Pinpoint. To see these metrics click here or in your Mobile Hub project click the Engage tab on the left of the screen.
Without any additional code, the Analytics module starts collect session data. All you need to do is to configure Analytics module.
To record an event, call the record
method:
import { Analytics } from 'aws-amplify';
Analytics.record('albumVisit');
The record
method lets you add additional attributes to an event. For example:
import { Analytics } from 'aws-amplify';
Analytics.record('albumVisit', { genre: '', artist: '' });
Metrics can also be added to an event:
import { Analytics } from 'aws-amplify';
Analytics.record('albumVisit', {}, { minutesListened: 30 });