Page updated Nov 9, 2023

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);
1AnalyticsEvent event = AnalyticsEvent.builder()
2 .name("PasswordReset")
3 .addProperty("Channel", "SMS")
4 .addProperty("Successful", true)
5 .addProperty("ProcessDuration", 792)
6 .addProperty("UserAge", 120.3)
7 .build();

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" } } } } }
2 "UserAgent": "aws-amplify-cli/2.0",
3 "Version": "1.0",
4 "analytics": {
5 "plugins": {
6 "awsPinpointAnalyticsPlugin": {
7 "pinpointAnalytics": {
8 "appId": "AppID",
9 "region": "Region",
10 "autoFlushEventsInterval": 10000
11 },
12 "pinpointTargeting": {
13 "region": "Region"
14 }
15 }
16 }
17 }

To manually flush events, call:


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>" } }
1"CognitoUserPool": {
2 "Default": {
3 "PoolId": "<poolid>",
4 "AppClientId": "<appclientid>",
5 "Region": "<region>",
6 "PinpointAppId": "<pinpointappid>"
7 }
  • 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); }
2* Call this method to log an authentication event to the analytics client.
4public void logAuthenticationEvent() {
5 AnalyticsEvent event = AnalyticsEvent.builder()
6 .name("_userauth.sign_in")
7 .build();
8 Amplify.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());
2 AnalyticsProperties.builder()
3 .add("AppStyle", "DarkMode")
4 .build());

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

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