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

Add analytics to monster registration #230

Merged
merged 2 commits into from
Jan 13, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package br.alexandregpereira.hunter.monster.registration

import br.alexandregpereira.hunter.analytics.Analytics

internal fun Analytics.trackMonsterRegistrationOpened(monsterIndex: String) {
track(
eventName = "MonsterRegistration - opened",
params = mapOf(
"monsterIndex" to monsterIndex,
),
)
}

internal fun Analytics.trackMonsterRegistrationClosed(monsterIndex: String) {
track(
eventName = "MonsterRegistration - closed",
params = mapOf(
"monsterIndex" to monsterIndex,
),
)
}

internal fun Analytics.trackMonsterRegistrationSaved(monsterIndex: String) {
track(
eventName = "MonsterRegistration - saved",
params = mapOf(
"monsterIndex" to monsterIndex,
),
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package br.alexandregpereira.hunter.monster.registration

import br.alexandregpereira.hunter.analytics.Analytics
import br.alexandregpereira.hunter.domain.model.Monster
import br.alexandregpereira.hunter.domain.usecase.GetMonsterUseCase
import br.alexandregpereira.hunter.domain.usecase.SaveMonstersUseCase
Expand All @@ -26,6 +27,7 @@ class MonsterRegistrationStateHolder internal constructor(
private val getMonster: GetMonsterUseCase,
private val saveMonsters: SaveMonstersUseCase,
private val normalizeMonster: NormalizeMonsterUseCase,
private val analytics: Analytics,
) : UiModel<MonsterRegistrationState>(MonsterRegistrationState()),
MutableActionHandler<MonsterRegistrationAction> by MutableActionHandler(),
MonsterRegistrationIntent {
Expand All @@ -46,6 +48,7 @@ class MonsterRegistrationStateHolder internal constructor(
}

override fun onSaved() {
analytics.trackMonsterRegistrationSaved(state.value.monster.index)
normalizeMonster(state.value.monster)
.flatMapConcat { monster ->
saveMonsters(monsters = listOf(monster))
Expand Down Expand Up @@ -77,8 +80,12 @@ class MonsterRegistrationStateHolder internal constructor(
.flowOn(dispatcher)
.onEach { event ->
when (event) {
MonsterRegistrationEvent.Hide -> setState { copy(isOpen = false) }
MonsterRegistrationEvent.Hide -> {
analytics.trackMonsterRegistrationClosed(state.value.monster.index)
setState { copy(isOpen = false) }
}
is MonsterRegistrationEvent.ShowEdit -> {
analytics.trackMonsterRegistrationOpened(event.monsterIndex)
params.value = MonsterRegistrationParams(monsterIndex = event.monsterIndex)
setState { copy(isOpen = true) }
loadMonster()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ val monsterRegistrationStateModule = module {
getMonster = get(),
saveMonsters = get(),
normalizeMonster = get(),
analytics = get(),
)
}
}
Expand Down
Loading