Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add method to track destination in Matomo #205

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading