amplitude / Amplitude-Kotlin

Amplitude Kotlin SDK
MIT License
27 stars 10 forks source link

feat: add autocapture for element clicks #199

Closed PouriaAmini closed 1 month ago

PouriaAmini commented 1 month ago

Summary

This PR removes support for Android SDKs 18 and below.

This PR adds the Autocapture feature to enable automatically tracking clicks on clickable element for the legacy Android View system and Jetpack Compose. This functionality is available to both new and existing users but is disabled by default. To enable it, set userInteractions in DefaultTrackingOptions to true:

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

Note: To use this feature, the @OptIn(ExperimentalAmplitudeFeature::class) is required to be added to the scope of the instance initialization, Activity class definition, or the entire file or module.

New automatically captured event

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

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

New automatically captured properties

[Amplitude] Element Class: (Android Views only) The canonical name of the underlying class of the clickable element, or the simple name as given in the source code if the canonical name is unavailable.

[Amplitude] Element Resource: (Android Views only) The entry name for the resource identifier of the clicked element.

[Amplitude] Element Tag: (Compose only) The Modifier.testTag specified for the clicked @Composable function.

[Amplitude] Element Source: (Android Views and Compose) The type of the origin of the clicked element, either "Android Views" for legacy Android Views or "Jetpack Compose" for Compose.

Checklist