Skip to content

Extension Functions

The library provides extension functions to track views and widgets in your application. Plugins can utilize these functions to log screen views and widget visibility events effectively.

trackPageView

The trackPageView function is used for tracking screen views. Each journey or plugin needs to call this function on their respective screens to log the screen view events. It requires a pluginName for logging, a screenName to identify the screen (ignored if null), and an optional payload (defaults to an empty JSON object). The isScreenUpdate flag updates the root screen name if true.

In Jetpack Compose, you can add trackPageView in the SideEffect of the main screen composable or within a LaunchedEffect block to ensure proper tracking of screen views. This is particularly useful in cases where temporary UI elements, such as bottom sheets, dialogs, or overlays, are dismissed, and the application needs to revert to the main screen context without updating the screen name. This approach ensures consistency in tracking and logging screen views, especially in complex UI flows.

Example :

kotlin
SideEffect {
    trackPageView(
        pluginName = HomeHubJourneyPlugin::class.java.simpleName,
        screenName = "MainScreen",
        isScreenUpdate = true
    )
}
kotlin
LaunchedEffect(Unit) {
    trackPageView(
        pluginName = HomeHubJourneyPlugin::class.java.simpleName,
        screenName = "MainScreen",
        isScreenUpdate = true
    )
}
kotlin
 trackPageView(
    HomeHubJourneyPlugin::class.java.simpleName,
    screenName
)

trackWidgetView

The trackWidgetView function is used to track the visibility of widgets in the application. It provides logging support for widget views, including details such as the plugin name, screen name, and widget name.

Example :

kotlin
 trackWidgetView(
    pluginName = HomeHubJourneyPlugin::class.java.simpleName,
    screenName = screenName,
    widgetName = widgetName,
)