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

Page updated May 10, 2024

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)

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

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 properties
Amplify.Analytics.unregisterGlobalProperties()
// Or you can specify which properties to unregister
let globalProperties = ["globalPropertyKey1", "globalPropertyKey2"]
Amplify.Analytics.unregisterGlobalProperties(globalProperties)