Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 2024

Record events

Record event

The Amplify analytics plugin also makes it easy to record custom events within the app. The plugin handles retry logic in the event the device loses network connectivity and automatically batches requests to reduce network bandwidth.

AnalyticsEvent event = AnalyticsEvent.builder()
.name("PasswordReset")
.addProperty("Channel", "SMS")
.addProperty("Successful", true)
.addProperty("ProcessDuration", 792)
.addProperty("UserAge", 120.3)
.build();
Amplify.Analytics.recordEvent(event);
val event = AnalyticsEvent.builder()
.name("PasswordReset")
.addProperty("Channel", "SMS")
.addProperty("Successful", true)
.addProperty("ProcessDuration", 792)
.addProperty("UserAge", 120.3)
.build()
Amplify.Analytics.recordEvent(event)
AnalyticsEvent event = AnalyticsEvent.builder()
.name("PasswordReset")
.addProperty("Channel", "SMS")
.addProperty("Successful", true)
.addProperty("ProcessDuration", 792)
.addProperty("UserAge", 120.3)
.build();
RxAmplify.Analytics.recordEvent(event);

The AWS Pinpoint event count updates in minutes after recording your event.

However, it can take upwards of 30 minutes for the event to display in the Filter section, and for its custom attributes to appear in Pinpoint.

Flush events

Events have default configuration to flush out to the network every 30 seconds. If you would like to change this, update amplifyconfiguration.json with the value in milliseconds you would like for autoFlushEventsInterval. This configuration will flush events every 10 seconds:

{
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"analytics": {
"plugins": {
"awsPinpointAnalyticsPlugin": {
"pinpointAnalytics": {
"appId": "AppID",
"region": "Region",
"autoFlushEventsInterval": 10000
},
"pinpointTargeting": {
"region": "Region"
}
}
}
}
}

To manually flush events, call:

Amplify.Analytics.flushEvents();
Amplify.Analytics.flushEvents()
RxAmplify.Analytics.flushEvents();

When flushing events, a Hub event is sent containing the events which were successfully sent to the Pinpoint service. To receive a list of these events, subscribe to the HubChannel.ANALYTICS channel and handle an event of the type AnalyticsChannelEventName.FLUSH_EVENTS.

Authentication events

Indicate how frequently users authenticate with your application.

On the Analytics page, the Users tab displays charts for Sign-ins, Sign-ups, and Authentication failures.

To learn how frequently users authenticate with your app, update your application code so that Pinpoint receives the following standard event types for authentication:

  • _userauth.sign_in
  • _userauth.sign_up
  • _userauth.auth_fail

You can report authentication events by doing either of the following:

  • Managing user sign-up and sign-in with Amazon Cognito user pools.

Cognito user pools are user directories that make it easier to add sign-up and sign-in to your app. As users authenticate with your app, Cognito reports authentication events to Pinpoint. For more information, see Using Amazon Pinpoint Analytics with Amazon Cognito User Pools in the Amazon Cognito Developer Guide. Also update amplifyconfiguration.json by adding the PinpointAppId key under CognitoUserPool.

"CognitoUserPool": {
"Default": {
"PoolId": "<poolid>",
"AppClientId": "<appclientid>",
"Region": "<region>",
"PinpointAppId": "<pinpointappid>"
}
}
  • Manually recording events using the recordEvent() API.

    If you don't want to use Cognito user pools, you can use the Pinpoint client to record and submit authentication events, as shown in the following examples. In these examples, the event type is set to _userauth.sign_in, but you can substitute any authentication event type.

/**
* Call this method to log an authentication event to the analytics client.
*/
public void logAuthenticationEvent() {
AnalyticsEvent event = AnalyticsEvent.builder()
.name("_userauth.sign_in")
.build();
Amplify.Analytics.recordEvent(event);
}
/**
* Call this method to log an authentication event to the analytics client.
*/
fun logAuthenticationEvent() {
val event = AnalyticsEvent.builder()
.name("_userauth.sign_in")
.build()
Amplify.Analytics.recordEvent(event)
}
/**
* Call this method to log an authentication event to the analytics client.
*/
public void logAuthenticationEvent() {
AnalyticsEvent event = AnalyticsEvent.builder()
.name("_userauth.sign_in")
.build();
RxAmplify.Analytics.recordEvent(event);
}

Global Properties

You can register global properties which will be sent along with all invocations of Amplify.Analytics.recordEvent.

Amplify.Analytics.registerGlobalProperties(
AnalyticsProperties.builder()
.add("AppStyle", "DarkMode")
.build());
Amplify.Analytics.registerGlobalProperties(
AnalyticsProperties.builder()
.add("AppStyle", "DarkMode")
.build())
RxAmplify.Analytics.registerGlobalProperties(
AnalyticsProperties.builder()
.add("AppStyle", "DarkMode")
.build());

To unregister a global property, call Amplify.Analytics.unregisterGlobalProperties():

Amplify.Analytics.unregisterGlobalProperties("AppStyle", "OtherProperty");
Amplify.Analytics.unregisterGlobalProperties("AppStyle", "OtherProperty")
RxAmplify.Analytics.unregisterGlobalProperties("AppStyle", "OtherProperty");