Skip to content

Commit

Permalink
chore: Add method to track destination
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Nov 20, 2024
1 parent dfe2f02 commit 817ab89
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Core2/Matomo/src/main/java/com/infomaniak/matomo/Matomo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ interface Matomo {
TrackHelper.track().screen(this).title(this::class.java.simpleName).with(tracker)
}

fun Context.trackScreen(path: String, title: String) {
TrackHelper.track().screen(path).title(title).with(tracker)
fun Context.trackScreen(path: String) {
TrackHelper.track().screen(path).with(tracker)
}
//endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@
*/
package com.infomaniak.swisstransfer.ui

import android.annotation.SuppressLint
import android.content.Context
import androidx.navigation.NavDestination
import com.infomaniak.matomo.Matomo
import com.infomaniak.swisstransfer.BuildConfig
import org.matomo.sdk.Tracker

object MatomoSwissTransfer : Matomo {

override val Context.tracker: Tracker get() = buildTracker() // TODO: Fetch appSettings for opt-out
override val siteId: Int = 24

// This `SuppressLint` is there so the CI can build
@SuppressLint("RestrictedApi")
fun Context.trackDestination(navDestination: NavDestination) = with(navDestination) {
route?.substringAfter("${BuildConfig.APPLICATION_ID}.ui.navigation.")?.let { path ->
trackScreen(path)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.infomaniak.swisstransfer.ui.MatomoSwissTransfer.trackDestination
import com.infomaniak.swisstransfer.ui.components.BrandTopAppBar
import com.infomaniak.swisstransfer.ui.navigation.MainNavigation
import com.infomaniak.swisstransfer.ui.navigation.NavigationDestination.Companion.toDestination
Expand All @@ -40,6 +42,8 @@ fun MainScreen() {
derivedStateOf { navBackStackEntry?.toDestination<MainNavigation>() ?: MainNavigation.startDestination }
}

navBackStackEntry?.destination?.let { LocalContext.current.trackDestination(it) }

MainScaffold(
navController = navController,
currentDestination = currentDestination,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@
package com.infomaniak.swisstransfer.ui.screen.newtransfer

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.infomaniak.swisstransfer.ui.MatomoSwissTransfer.trackDestination
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows

@Composable
fun NewTransferScreen(closeActivity: () -> Unit) {
val navController = rememberNavController()

val navBackStackEntry by navController.currentBackStackEntryAsState()

navBackStackEntry?.destination?.let { LocalContext.current.trackDestination(it) }

NewTransferNavHost(navController, closeActivity)
}

Expand Down

0 comments on commit 817ab89

Please sign in to comment.