Record events
Record Event
The Amplify Analytics plugin provides a simple interface to record custom events within your app:
let properties: AnalyticsProperties = [ "eventPropertyStringKey": "eventPropertyStringValue", "eventPropertyIntKey": 123, "eventPropertyDoubleKey": 12.34, "eventPropertyBoolKey": true]
let event = BasicAnalyticsEvent( name: "eventName", properties: properties)
Amplify.Analytics.record(event: event)
Flush Events
By default, events are automatically flushed out to the network every 60 seconds.
You can change this through the options
parameter when initializing the plugin, by creating a AWSPinpointAnalyticsPlugin.Options
instance and setting its autoFlushEventsInterval
property to the desired value, expressed in seconds:
let options = AWSPinpointAnalyticsPlugin.Options( autoFlushEventsInterval: 60)try Amplify.add(plugin: AWSPinpointAnalyticsPlugin(options: options))
Note
Setting
autoFlushEventsInterval
to 0 will disable the automatic flush of events and you will be responsible for submitting them.
To manually submit the recoded events to the backend, call:
Amplify.Analytics.flushEvents()
The plugin automatically batches requests in order to reduce network bandwidth and handles the retry logic if the device loses connectivity.
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 these events by doing the following:
let event = BasicAnalyticsEvent( name: "_userauth.sign_in" // Or any of the accepted values)Amplify.Analytics.record(event: event)
Global Properties
You can register properties which will be included across all Amplify.Analytics.record(event:)
calls.
let globalProperties: AnalyticsProperties = [ "globalPropertyKey": "value"]Amplify.Analytics.registerGlobalProperties(globalProperties)
To unregister global properties, call Amplify.Analytics.unregisterGlobalProperties()
:
// When called with no arguments, it unregisters all global propertiesAmplify.Analytics.unregisterGlobalProperties()
// Or you can specify which properties to unregisterlet globalProperties = ["globalPropertyKey1", "globalPropertyKey2"]Amplify.Analytics.unregisterGlobalProperties(globalProperties)