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.
To create a project fully functioning with the Analytics category.
$ npm install -g awsmobile-cli
$ cd my-app
$ awsmobile init
$ awsmobile enable analytics
$ awsmobile push
In your project i.e. App.js:
import Amplify, { Analytics } from 'aws-amplify';
import aws_exports from './aws-exports';
Amplify.configure(aws_exports);
import Amplify from 'aws-amplify';
Amplify.configure(
Analytics: {
// OPTIONAL - Amazon Pinpoint App ID
appId: 'XXXXXXXXXXabcdefghij1234567890ab',
// OPTIONAL - Amazon service region
region: 'XX-XXXX-X',
}
);
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.
After configuration, user session metrics are automatically collected and sent to Amazon Pinpoint. To see these metrics click here, or on the cli (from your project directory):
$ awsmobile console
Then click Analytics.
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 });