TrackScreenViews

fun NavController.TrackScreenViews(screenName: (NavDestination) -> String? = { it.route })

Automatically records a Screen Viewed event for every destination change of this NavController (androidx.navigation, a.k.a. navigation-compose).

val navController = rememberNavController()
navController.TrackScreenViews()
NavHost(navController, startDestination = "home") { ... }

Parameters

screenName

maps a destination to a screen name; return null to skip tracking that destination. Defaults to the destination route.