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

Page updated Jun 28, 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 looses network connectivity and automatically batches requests to reduce network bandwidth.

Future<void> recordCustomEvent() async {
final event = AnalyticsEvent('PasswordReset');
event.customProperties
..addStringProperty('Channel', 'SMS')
..addBoolProperty('Successful', true);
// You can also add the properties one by one like the following
event.customProperties.addIntProperty('ProcessDuration', 792);
event.customProperties.addDoubleProperty('doubleKey', 120.3);
await Amplify.Analytics.recordEvent(event: event);
}

The Amazon 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 Amazon Pinpoint.

Flush events

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

{
"Version": "1.0",
"analytics": {
"plugins": {
"awsPinpointAnalyticsPlugin": {
"pinpointAnalytics": {
"appId": "<your-app-id>",
"region": "<your-app-region>"
},
"pinpointTargeting": {
"region": "<your-app-region>"
},
"autoFlushEventsInterval": 10
}
}
}
}

Note

Setting autoFlushEventsInterval to 0 will disable the automatic flush of events and you will be responsible for submitting them.

To manually flush events, call:

await Amplify.Analytics.flushEvents();

Global Properties

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

Future<void> registerGlobalProperties() async {
final properties = CustomProperties()
..addStringProperty('AppStyle', 'DarkMode');
await Amplify.Analytics.registerGlobalProperties(
globalProperties: properties,
);
}

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

Future<void> unregisterGlobalProperties() async {
await Amplify.Analytics.unregisterGlobalProperties(
propertyNames: ['AppStyle', 'OtherProperty'],
);
}

Furthermore, you can remove all global properties by calling unregisterGlobalProperties without propertyNames:

Future<void> unregisterAllGlobalProperties() async {
await Amplify.Analytics.unregisterGlobalProperties();
}