package com.suno.android.utils.resolvers import com.suno.android.common_analytics.model.ScreenTrackingName import com.suno.android.common_analytics.model.TrackingName import com.suno.android.ui.screens.navigation.NavDestination import com.suno.android.ui.screens.navigation.NavDestination.Billing import com.suno.android.ui.screens.navigation.NavDestination.Create import com.suno.android.ui.screens.navigation.NavDestination.Home import com.suno.android.ui.screens.navigation.NavDestination.Landing import com.suno.android.ui.screens.navigation.NavDestination.LoggedInNav import com.suno.android.ui.screens.navigation.NavDestination.Onboarding import com.suno.android.ui.screens.navigation.NavDestination.Profile import com.suno.android.ui.screens.navigation.NavDestination.Settings import kotlinx.collections.immutable.persistentMapOf import javax.inject.Inject /** * Obtains the [TrackingName] for a screen by resolving its NavDestination route. */ interface ScreenVisitResolver { fun resolve( route: String?, ): TrackingName? } class DefaultScreenVisitResolver @Inject constructor() : ScreenVisitResolver { override fun resolve( route: String?, ) = ScreenVisitTracking.getTrackingName(route)?.value?.let(::TrackingName) } object ScreenVisitTracking { // Includes screens important for analytics, does not include NavGraphs. private val routeToTrackingName: Map = persistentMapOf( // Landing Landing.WelcomeScreenDestination::class.qualifiedName to ScreenTrackingName.WELCOME, Landing.LoginScreenDestination::class.qualifiedName to ScreenTrackingName.LOGIN, Landing.TermsDestination::class.qualifiedName to ScreenTrackingName.LANDING_TERMS, Landing.PrivacyPolicyDestination::class.qualifiedName to ScreenTrackingName.LANDING_PRIVACY_POLICY, Landing.ExternalOauthScreenDestination::class.qualifiedName to ScreenTrackingName.EXTERNAL_OAUTH, Landing.InputPhoneNumberDestination::class.qualifiedName to ScreenTrackingName.INPUT_PHONE_NUMBER, Landing.ValidatePhoneNumberDestination::class.qualifiedName to ScreenTrackingName.VALIDATE_PHONE_NUMBER, // Onboarding Onboarding.WhatsYourNameScreenDestination::class.qualifiedName to ScreenTrackingName.ONBOARDING_WHATS_YOUR_NAME, Onboarding.UsernameHandleScreenDestination::class.qualifiedName to ScreenTrackingName.ONBOARDING_USERNAME_HANDLE, Onboarding.AddProfilePhotoScreenDestination::class.qualifiedName to ScreenTrackingName.ONBOARDING_ADD_PROFILE_PHOTO, Onboarding.AllowNotificationsScreenDestination::class.qualifiedName to ScreenTrackingName.ONBOARDING_ALLOW_NOTIFICATIONS, // Create Create.WorkspacesScreenDestination::class.qualifiedName to ScreenTrackingName.WORKSPACES, Create.CreateScreenModeSelectionDestination::class.qualifiedName to ScreenTrackingName.CREATE_SCREEN_MODE_SELECTION, Create.WorkspacesSearchScreenDestination::class.qualifiedName to ScreenTrackingName.WORKSPACES_SEARCH, // Profile Profile.ProfileScreenDestination::class.qualifiedName to ScreenTrackingName.PROFILE, Profile.EditProfileScreenDestination::class.qualifiedName to ScreenTrackingName.EDIT_PROFILE, // Settings Settings.SettingsScratchScreenDestination::class.qualifiedName to ScreenTrackingName.SETTINGS_SCRATCH, Settings.SettingsOverviewScreenDestination::class.qualifiedName to ScreenTrackingName.SETTINGS_OVERVIEW, Settings.SettingsAppearanceScreenDestination::class.qualifiedName to ScreenTrackingName.SETTINGS_APPEARANCE, Settings.SettingsSupportLinkScreenDestination::class.qualifiedName to ScreenTrackingName.SETTINGS_SUPPORT_LINK, Settings.SettingsEasterScreenDestination::class.qualifiedName to ScreenTrackingName.SETTINGS_EASTER, // Billing Billing.BillingOptionsScreenDestination::class.qualifiedName to ScreenTrackingName.BILLING_OPTIONS, Billing.BillingTopUpScreenDestination::class.qualifiedName to ScreenTrackingName.BILLING_TOP_UP, Billing.BillingStripeRedirect::class.qualifiedName to ScreenTrackingName.BILLING_STRIPE_REDIRECT, Billing.TermsDestination::class.qualifiedName to ScreenTrackingName.BILLING_TERMS, Billing.PrivacyPolicyDestination::class.qualifiedName to ScreenTrackingName.BILLING_PRIVACY_POLICY, Billing.ContactUsDestination::class.qualifiedName to ScreenTrackingName.CONTACT_US, // Home Home.ExploreScreenDestination::class.qualifiedName to ScreenTrackingName.EXPLORE, Home.ExploreSearchScreenDestination::class.qualifiedName to ScreenTrackingName.EXPLORE_SEARCH, Home.ExploreNotificationScreenDestination::class.qualifiedName to ScreenTrackingName.EXPLORE_NOTIFICATION, Home.LibraryScreenDestination::class.qualifiedName to ScreenTrackingName.LIBRARY, Home.LibrarySearchScreenDestination::class.qualifiedName to ScreenTrackingName.LIBRARY_SEARCH, Home.MyProfileScreenDestination::class.qualifiedName to ScreenTrackingName.MY_PROFILE, Home.PlaylistsCollectionScreenDestination::class.qualifiedName to ScreenTrackingName.PLAYLISTS_COLLECTION, Home.PlaylistScreenDestination::class.qualifiedName to ScreenTrackingName.PLAYLIST, Home.NotificationScreenDestination::class.qualifiedName to ScreenTrackingName.NOTIFICATION, Home.HooksFeedScreenDestination::class.qualifiedName to ScreenTrackingName.HOOKS, // LoggedIn LoggedInNav.OmniScreenDestination::class.qualifiedName to ScreenTrackingName.OMNIPLAYER, LoggedInNav.ShareAssetEditorDestination::class.qualifiedName to ScreenTrackingName.SHARE_ASSET_EDITOR, // Splash NavDestination.SplashScreenDestination::class.qualifiedName to ScreenTrackingName.SPLASH, ) fun getTrackingName( route: String?, ): ScreenTrackingName? { if (route == null) return null val truncatedRoute = route .substringBefore('?') .substringBefore('/') return routeToTrackingName[route] ?: routeToTrackingName[truncatedRoute] ?: routeToTrackingName.entries.firstOrNull { (key, _) -> key?.let { key.startsWith(truncatedRoute) } ?: false }?.value } }