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).
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.
amplify add analytics
amplify push
Expand Gradle Scripts, open build.gradle (Module: app). You will already have configured Amplify by following the steps in the Project Setup walkthrough.
Add Analytics by adding these libraries into the dependencies block:
dependencies {
// Add these lines in `dependencies`
implementation 'com.amplifyframework:aws-analytics-pinpoint:1.24.0'
implementation 'com.amplifyframework:aws-auth-cognito:1.24.0'
}
Add the following code to your onCreate() method in your application class:
Amplify.addPlugin(new AWSCognitoAuthPlugin());
Amplify.addPlugin(new AWSPinpointAnalyticsPlugin(this));
AnalyticsEvent event = AnalyticsEvent.builder()
.name("PasswordReset")
.addProperty("Channel", "SMS")
.addProperty("Successful", true)
.addProperty("ProcessDuration", 792)
.addProperty("UserAge", 120.3)
.build();
Amplify.Analytics.recordEvent(event);
From the terminal run the following command. Navigate to the Analytics tab, and then choose View in Pinpoint.
amplify console analytics
AnalyticsEvent event = AnalyticsEvent.builder()
.name("PasswordReset")
.addProperty("Channel", "SMS")
.addProperty("Successful", true)
.addProperty("ProcessDuration", 792)
.addProperty("UserAge", 120.3)
.build();
Amplify.Analytics.recordEvent(event);
{
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"analytics": {
"plugins": {
"awsPinpointAnalyticsPlugin": {
"pinpointAnalytics": {
"appId": "AppID",
"region": "Region"
},
"pinpointTargeting": {
"region": "Region"
},
"autoFlushEventsInterval": 10000
}
}
}
}
Amplify.Analytics.flushEvents();