Record events
Record event
The Amplify Analytics plugin makes it easy to record custom events within an app. The plugin handles retry logic in the event that the device loses network connectivity, and it automatically batches requests to reduce network bandwidth.
AnalyticsEvent event = AnalyticsEvent.builder() .name("PasswordReset") .addProperty("Channel", "SMS") .addProperty("Successful", true) .addProperty("ProcessDuration", 792) .addProperty("UserAge", 120.3) .build();
Amplify.Analytics.recordEvent(event);
val event = AnalyticsEvent.builder() .name("PasswordReset") .addProperty("Channel", "SMS") .addProperty("Successful", true) .addProperty("ProcessDuration", 792) .addProperty("UserAge", 120.3) .build()
Amplify.Analytics.recordEvent(event)
AnalyticsEvent event = AnalyticsEvent.builder() .name("PasswordReset") .addProperty("Channel", "SMS") .addProperty("Successful", true) .addProperty("ProcessDuration", 792) .addProperty("UserAge", 120.3) .build();
RxAmplify.Analytics.recordEvent(event);
Flush events
Events have a default configuration to flush out to the network every 30 seconds. You can change this value by passing the autoFlushEventsInterval
option to the AWSPinpointAnalyticsPlugin
. The option value is measured in milliseconds.
val options = AWSPinpointAnalyticsPlugin.Options { autoFlushEventsInterval = 60_000}Amplify.addPlugin(AWSPinpointAnalyticsPlugin(options))Amplify.configure(AmplifyOutputs(R.raw.amplify_outputs), this)
To manually flush events, call:
Amplify.Analytics.flushEvents();
Amplify.Analytics.flushEvents()
RxAmplify.Analytics.flushEvents();
When flushing events, a Hub event is sent containing the events which were successfully sent to the Pinpoint service. To receive a list of these events, subscribe to the HubChannel.ANALYTICS
channel and handle an event of the type AnalyticsChannelEventName.FLUSH_EVENTS
.
Global Properties
You can register global properties which will be sent along with all invocations of Amplify.Analytics.recordEvent
.
Amplify.Analytics.registerGlobalProperties( AnalyticsProperties.builder() .add("AppStyle", "DarkMode") .build());
Amplify.Analytics.registerGlobalProperties( AnalyticsProperties.builder() .add("AppStyle", "DarkMode") .build())
RxAmplify.Analytics.registerGlobalProperties( AnalyticsProperties.builder() .add("AppStyle", "DarkMode") .build());
To unregister a global property, call Amplify.Analytics.unregisterGlobalProperties()
:
Amplify.Analytics.unregisterGlobalProperties("AppStyle", "OtherProperty");
Amplify.Analytics.unregisterGlobalProperties("AppStyle", "OtherProperty")
RxAmplify.Analytics.unregisterGlobalProperties("AppStyle", "OtherProperty");