## 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 loses network connectivity and automatically batches requests to reduce network bandwidth. ```java AnalyticsEvent event = AnalyticsEvent.builder() .name("PasswordReset") .addProperty("Channel", "SMS") .addProperty("Successful", true) .addProperty("ProcessDuration", 792) .addProperty("UserAge", 120.3) .build(); Amplify.Analytics.recordEvent(event); ``` ```kotlin val event = AnalyticsEvent.builder() .name("PasswordReset") .addProperty("Channel", "SMS") .addProperty("Successful", true) .addProperty("ProcessDuration", 792) .addProperty("UserAge", 120.3) .build() Amplify.Analytics.recordEvent(event) ``` ```java 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 default configuration to flush out to the network every 30 seconds. If you would like to change this, update `amplifyconfiguration.json` with the value in milliseconds you would like for `autoFlushEventsInterval`. This configuration will flush events every 10 seconds: ```json { "UserAgent": "aws-amplify-cli/2.0", "Version": "1.0", "analytics": { "plugins": { "awsPinpointAnalyticsPlugin": { "pinpointAnalytics": { "appId": "AppID", "region": "Region", "autoFlushEventsInterval": 10000 }, "pinpointTargeting": { "region": "Region" } } } } } ``` To manually flush events, call: ```java Amplify.Analytics.flushEvents(); ``` ```kotlin Amplify.Analytics.flushEvents() ``` ```java RxAmplify.Analytics.flushEvents(); ``` When flushing events, a [Hub event](/lib/utilities/hub) 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`. ## Authentication events import native_common from "/src/fragments/lib-v1/analytics/native_common/getting-started/auth-events.mdx"; ```java /** * Call this method to log an authentication event to the analytics client. */ public void logAuthenticationEvent() { AnalyticsEvent event = AnalyticsEvent.builder() .name("_userauth.sign_in") .build(); Amplify.Analytics.recordEvent(event); } ``` ```kotlin /** * Call this method to log an authentication event to the analytics client. */ fun logAuthenticationEvent() { val event = AnalyticsEvent.builder() .name("_userauth.sign_in") .build() Amplify.Analytics.recordEvent(event) } ``` ```java /** * Call this method to log an authentication event to the analytics client. */ public void logAuthenticationEvent() { AnalyticsEvent event = AnalyticsEvent.builder() .name("_userauth.sign_in") .build(); RxAmplify.Analytics.recordEvent(event); } ``` ## Global Properties You can register global properties which will be sent along with all invocations of `Amplify.Analytics.recordEvent`. ```java Amplify.Analytics.registerGlobalProperties( AnalyticsProperties.builder() .add("AppStyle", "DarkMode") .build()); ``` ```kotlin Amplify.Analytics.registerGlobalProperties( AnalyticsProperties.builder() .add("AppStyle", "DarkMode") .build()) ``` ```java RxAmplify.Analytics.registerGlobalProperties( AnalyticsProperties.builder() .add("AppStyle", "DarkMode") .build()); ``` To unregister a global property, call `Amplify.Analytics.unregisterGlobalProperties()`: ```java Amplify.Analytics.unregisterGlobalProperties("AppStyle", "OtherProperty"); ``` ```kotlin Amplify.Analytics.unregisterGlobalProperties("AppStyle", "OtherProperty") ``` ```java RxAmplify.Analytics.unregisterGlobalProperties("AppStyle", "OtherProperty"); ```