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.
1Future<void> recordCustomEvent() async {2 final event = AnalyticsEvent('PasswordReset');3
4 event.properties5 ..addStringProperty('Channel', 'SMS')6 ..addBoolProperty('Successful', true);7
8 // You can also add the properties one by one like the following9 event.properties.addIntProperty('ProcessDuration', 792);10 event.properties.addDoubleProperty('doubleKey', 120.3);11
12 await Amplify.Analytics.recordEvent(event: event);13}
Flush events
To manually flush events, call:
1await Amplify.Analytics.flushEvents();
Global Properties
You can register global properties which will be sent along with all invocations of Amplify.Analytics.recordEvent
.
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()
:
1Future<void> unregisterGlobalProperties() async {2 await Amplify.Analytics.unregisterGlobalProperties(3 propertyNames: ['AppStyle', 'OtherProperty'],4 );5}