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

Page updated Apr 29, 2024

Record events

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

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

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

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 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.dart 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"
},
"pinpointTargeting": {
"region": "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();
}