Skip to content

Commit

Permalink
feat: 통계 GA
Browse files Browse the repository at this point in the history
  • Loading branch information
yangsooplus committed Feb 19, 2024
1 parent 528557e commit fab0bca
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
3 changes: 3 additions & 0 deletions feature/statistics/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ 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
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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
),
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit fab0bca

Please sign in to comment.