Page updated Nov 9, 2023

Record events

Amplify Flutter v0 is now in Maintenance Mode until July 19th, 2024. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v0.

Please use the latest version (v1) of Amplify Flutter to get started.

If you are currently using v0, follow these instructions to upgrade to v1.

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.properties ..addStringProperty('Channel', 'SMS') ..addBoolProperty('Successful', true); // You can also add the properties one by one like the following event.properties.addIntProperty('ProcessDuration', 792); event.properties.addDoubleProperty('doubleKey', 120.3); await Amplify.Analytics.recordEvent(event: event); }
1Future<void> recordCustomEvent() async {
2 final event = AnalyticsEvent('PasswordReset');
3
4 event.properties
5 ..addStringProperty('Channel', 'SMS')
6 ..addBoolProperty('Successful', true);
7
8 // You can also add the properties one by one like the following
9 event.properties.addIntProperty('ProcessDuration', 792);
10 event.properties.addDoubleProperty('doubleKey', 120.3);
11
12 await Amplify.Analytics.recordEvent(event: event);
13}

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

To manually flush events, call:

await Amplify.Analytics.flushEvents();
1await 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 = AnalyticsProperties() ..addStringProperty('AppStyle', 'DarkMode'); await Amplify.Analytics.registerGlobalProperties( globalProperties: properties, ); }
1Future<void> registerGlobalProperties() async {
2 final properties = AnalyticsProperties()
3 ..addStringProperty('AppStyle', 'DarkMode');
4 await Amplify.Analytics.registerGlobalProperties(
5 globalProperties: properties,
6 );
7}

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

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