amplitude / Amplitude-Kotlin

Amplitude Kotlin SDK
MIT License
27 stars 10 forks source link

feat: add scroll and swipe autocapture #201

Closed PouriaAmini closed 1 month ago

PouriaAmini commented 1 month ago

Summary

This PR adds support for scroll and swipe autocapture. The functionality is enabled by default when userInteractions is set to true in DefaultTrackingOptions.

@OptIn(ExperimentalAmplitudeFeature::class)
Amplitude(
    Configuration(
        apiKey = AMPLITUDE_API_KEY,
        context = applicationContext,
        defaultTracking = DefaultTrackingOptions(
            userInteractions = true
        )
    )
)

New automatically captured event

[Amplitude] Element Scrolled: Emitted when a user scrolls on a scrollable element in the legacy Android View system or a tagged scrollable @Composable functions in Compose.

[Amplitude] Element Swiped: Emitted when a user flings on a UI element that was previously scrolled/moved.

Note: To capture the event in Compose, the scrollable @Composable functions must include a Modifier.testTag, otherwise the event will not be captured. Scrollable @Composable functions have an ScrollBy lambda or a Modifier.scrollable modifier (for Jetpack Compose > 1.5).

New automatically captured properties

[Amplitude] Direction: (Android Views and Compose) The direction of the scroll or swipe (Up, Right, Down, Left).

Optimizations around Autocapture implementations

  1. Resource name has a fallback now in case a resourceEntryName does not exist.
  2. Reflection is done lazily for Compose internals.

Checklist