diff --git a/feature/statistics/src/main/AndroidManifest.xml b/feature/statistics/src/main/AndroidManifest.xml index 8bdb7e14..31c45c66 100644 --- a/feature/statistics/src/main/AndroidManifest.xml +++ b/feature/statistics/src/main/AndroidManifest.xml @@ -1,4 +1,7 @@ + + + diff --git a/feature/statistics/src/main/java/com/susu/feature/statistics/StatisticsScreen.kt b/feature/statistics/src/main/java/com/susu/feature/statistics/StatisticsScreen.kt index 4b6d0eca..2f99174d 100644 --- a/feature/statistics/src/main/java/com/susu/feature/statistics/StatisticsScreen.kt +++ b/feature/statistics/src/main/java/com/susu/feature/statistics/StatisticsScreen.kt @@ -16,8 +16,10 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.core.os.bundleOf import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.google.firebase.analytics.FirebaseAnalytics import com.susu.core.designsystem.component.appbar.SusuDefaultAppBar import com.susu.core.designsystem.component.appbar.icon.LogoIcon import com.susu.core.designsystem.component.screen.LoadingScreen @@ -58,6 +60,15 @@ fun StatisticsRoute( viewModel.checkAdditionalInfo() } + LaunchedEffect(key1 = uiState.currentTab) { + FirebaseAnalytics.getInstance(context).logEvent( + FirebaseAnalytics.Event.SCREEN_VIEW, + bundleOf( + FirebaseAnalytics.Param.SCREEN_NAME to "statistics_${uiState.currentTab}", + ), + ) + } + StatisticsScreen( padding = padding, uiState = uiState, diff --git a/feature/statistics/src/main/java/com/susu/feature/statistics/content/susu/SusuStatisticsContent.kt b/feature/statistics/src/main/java/com/susu/feature/statistics/content/susu/SusuStatisticsContent.kt index b78b1af8..a4378622 100644 --- a/feature/statistics/src/main/java/com/susu/feature/statistics/content/susu/SusuStatisticsContent.kt +++ b/feature/statistics/src/main/java/com/susu/feature/statistics/content/susu/SusuStatisticsContent.kt @@ -24,6 +24,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll @@ -31,8 +32,10 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.core.os.bundleOf import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.google.firebase.analytics.FirebaseAnalytics import com.susu.core.designsystem.component.bottomsheet.SusuSelectionBottomSheet import com.susu.core.designsystem.component.screen.LoadingScreen import com.susu.core.designsystem.theme.Blue60 @@ -47,6 +50,7 @@ import com.susu.feature.statistics.component.StatisticsHorizontalItem import com.susu.feature.statistics.component.StatisticsVerticalItem import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toPersistentList +import kotlinx.coroutines.launch @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -57,6 +61,8 @@ fun SusuStatisticsRoute( handleException: (Throwable, () -> Unit) -> Unit, ) { val uiState by viewModel.uiState.collectAsStateWithLifecycle() + val scope = rememberCoroutineScope() + val context = LocalContext.current val refreshState = rememberPullToRefreshState( positionalThreshold = 100.dp, @@ -65,6 +71,35 @@ fun SusuStatisticsRoute( viewModel.sideEffect.collectWithLifecycle { sideEffect -> when (sideEffect) { is SusuStatisticsEffect.HandleException -> handleException(sideEffect.throwable, sideEffect.retry) + is SusuStatisticsEffect.LogAgeOption -> scope.launch { + FirebaseAnalytics.getInstance(context).logEvent( + FirebaseAnalytics.Event.SELECT_CONTENT, + bundleOf( + FirebaseAnalytics.Param.CONTENT_TYPE to "statistics_age", + FirebaseAnalytics.Param.VALUE to sideEffect.age, + ), + ) + } + + is SusuStatisticsEffect.LogCategoryOption -> scope.launch { + FirebaseAnalytics.getInstance(context).logEvent( + FirebaseAnalytics.Event.SELECT_CONTENT, + bundleOf( + FirebaseAnalytics.Param.CONTENT_TYPE to "statistics_category", + FirebaseAnalytics.Param.VALUE to sideEffect.category, + ), + ) + } + + is SusuStatisticsEffect.LogRelationshipOption -> scope.launch { + FirebaseAnalytics.getInstance(context).logEvent( + FirebaseAnalytics.Event.SELECT_CONTENT, + bundleOf( + FirebaseAnalytics.Param.CONTENT_TYPE to "statistics_relationship", + FirebaseAnalytics.Param.VALUE to sideEffect.relationship, + ), + ) + } } } diff --git a/feature/statistics/src/main/java/com/susu/feature/statistics/content/susu/SusuStatisticsContract.kt b/feature/statistics/src/main/java/com/susu/feature/statistics/content/susu/SusuStatisticsContract.kt index a85bb3ca..47139a97 100644 --- a/feature/statistics/src/main/java/com/susu/feature/statistics/content/susu/SusuStatisticsContract.kt +++ b/feature/statistics/src/main/java/com/susu/feature/statistics/content/susu/SusuStatisticsContract.kt @@ -10,6 +10,9 @@ import kotlinx.collections.immutable.persistentListOf sealed interface SusuStatisticsEffect : SideEffect { data class HandleException(val throwable: Throwable, val retry: () -> Unit) : SusuStatisticsEffect + data class LogAgeOption(val age: StatisticsAge) : SusuStatisticsEffect + data class LogRelationshipOption(val relationship: String) : SusuStatisticsEffect + data class LogCategoryOption(val category: String) : SusuStatisticsEffect } data class SusuStatisticsState( diff --git a/feature/statistics/src/main/java/com/susu/feature/statistics/content/susu/SusuStatisticsViewModel.kt b/feature/statistics/src/main/java/com/susu/feature/statistics/content/susu/SusuStatisticsViewModel.kt index 49ee90e6..81c296f5 100644 --- a/feature/statistics/src/main/java/com/susu/feature/statistics/content/susu/SusuStatisticsViewModel.kt +++ b/feature/statistics/src/main/java/com/susu/feature/statistics/content/susu/SusuStatisticsViewModel.kt @@ -69,9 +69,20 @@ class SusuStatisticsViewModel @Inject constructor( } } - fun selectAge(age: StatisticsAge) = intent { copy(age = age, isAgeSheetOpen = false) } - fun selectRelationship(index: Int) = intent { copy(relationship = relationshipConfig[index], isRelationshipSheetOpen = false) } - fun selectCategory(index: Int) = intent { copy(category = categoryConfig[index], isCategorySheetOpen = false) } + fun selectAge(age: StatisticsAge) { + intent { copy(age = age, isAgeSheetOpen = false) } + postSideEffect(SusuStatisticsEffect.LogAgeOption(currentState.age)) + } + fun selectRelationship(index: Int) { + intent { copy(relationship = relationshipConfig[index], isRelationshipSheetOpen = false) } + postSideEffect(SusuStatisticsEffect.LogRelationshipOption(currentState.relationship.relation)) + } + + fun selectCategory(index: Int) { + intent { copy(category = categoryConfig[index], isCategorySheetOpen = false) } + postSideEffect(SusuStatisticsEffect.LogCategoryOption(currentState.category.category)) + } + fun showAgeSheet() = intent { copy(isAgeSheetOpen = true) } fun showRelationshipSheet() = intent { copy(isRelationshipSheetOpen = true) } fun showCategorySheet() = intent { copy(isCategorySheetOpen = true) }