diff --git a/feature/monster-registration/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/monster/registration/MonsterRegistrationAnalytics.kt b/feature/monster-registration/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/monster/registration/MonsterRegistrationAnalytics.kt new file mode 100644 index 00000000..cd8ced5c --- /dev/null +++ b/feature/monster-registration/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/monster/registration/MonsterRegistrationAnalytics.kt @@ -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, + ), + ) +} diff --git a/feature/monster-registration/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/monster/registration/MonsterRegistrationStateHolder.kt b/feature/monster-registration/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/monster/registration/MonsterRegistrationStateHolder.kt index 1127b6b8..2d3ee06f 100644 --- a/feature/monster-registration/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/monster/registration/MonsterRegistrationStateHolder.kt +++ b/feature/monster-registration/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/monster/registration/MonsterRegistrationStateHolder.kt @@ -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 @@ -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()), MutableActionHandler by MutableActionHandler(), MonsterRegistrationIntent { @@ -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)) @@ -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() diff --git a/feature/monster-registration/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/monster/registration/di/Module.kt b/feature/monster-registration/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/monster/registration/di/Module.kt index 8af19907..4bda3948 100644 --- a/feature/monster-registration/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/monster/registration/di/Module.kt +++ b/feature/monster-registration/state-holder/src/commonMain/kotlin/br/alexandregpereira/hunter/monster/registration/di/Module.kt @@ -49,6 +49,7 @@ val monsterRegistrationStateModule = module { getMonster = get(), saveMonsters = get(), normalizeMonster = get(), + analytics = get(), ) } }