Skip to content

Commit f9a6bda

Browse files
committed
feat: track error modals shown in app via analytics event
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 841565f commit f9a6bda

6 files changed

Lines changed: 52 additions & 3 deletions

File tree

apps/flipcash/app/src/main/kotlin/com/flipcash/app/internal/ui/navigation/decorators/NavMessagingEntryDecorator.kt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,48 @@ import androidx.compose.runtime.remember
66
import androidx.navigation3.runtime.NavBackStack
77
import androidx.navigation3.runtime.NavEntryDecorator
88
import androidx.navigation3.runtime.NavKey
9+
import com.flipcash.app.analytics.rememberAnalytics
10+
import com.getcode.manager.BottomBarManager
911
import com.getcode.navigation.NavMetadataKeys
1012
import com.getcode.ui.components.bars.BarManager
1113
import com.getcode.ui.components.bars.BottomBarContainer
1214
import com.getcode.ui.components.bars.TopBarContainer
15+
import com.getcode.utils.TraceType
16+
import com.getcode.utils.trace
1317

1418
@Suppress("FunctionName")
1519
fun NavMessagingEntryDecorator(
1620
backStack: NavBackStack<NavKey>,
1721
barManager: BarManager
1822
): NavEntryDecorator<NavKey> {
1923
return NavEntryDecorator { entry ->
24+
val analytics = rememberAnalytics()
2025
Box {
2126
entry.Content()
2227
val isTopEntry = entry.contentKey == backStack.lastOrNull()?.toString()
2328
if (isTopEntry && entry.metadata[NavMetadataKeys.IsSheet.key] != true) {
24-
TopBarContainer(barManager.barMessages)
25-
BottomBarContainer(barManager.barMessages)
29+
BottomBarContainer(barManager.barMessages) { message ->
30+
trace(
31+
message = "bottom bar message shown [${message.type.name}]",
32+
metadata = {
33+
"title" to message.title
34+
"message" to message.subtitle
35+
"type" to message.type.name
36+
"additionalInfo" to message.additionalInfo
37+
},
38+
type = TraceType.Process,
39+
)
40+
when (message.type) {
41+
BottomBarManager.BottomBarMessageType.DESTRUCTIVE -> Unit
42+
BottomBarManager.BottomBarMessageType.ERROR -> {
43+
analytics.displayedErrorModal(message.title, message.subtitle)
44+
}
45+
BottomBarManager.BottomBarMessageType.WARNING -> Unit
46+
BottomBarManager.BottomBarMessageType.INFO -> Unit
47+
BottomBarManager.BottomBarMessageType.DEFAULT -> Unit
48+
BottomBarManager.BottomBarMessageType.SUCCESS -> Unit
49+
}
50+
}
2651
}
2752
}
2853
}

apps/flipcash/shared/analytics/src/main/kotlin/com/flipcash/app/analytics/Analytics.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface FlipcashAnalyticsService : AnalyticsService {
3232
fun deeplinkOpened(url: String)
3333
fun deeplinkParsed(type: DeeplinkType?, url: String)
3434
fun deeplinkRouted(type: DeeplinkType, error: Throwable? = null)
35+
fun displayedErrorModal(title: String, message: String)
3536

3637
fun buttonTapped(button: Button) {
3738
action(button)
@@ -98,6 +99,7 @@ class StubFlipcashAnalytics : FlipcashAnalyticsService {
9899
override fun deeplinkOpened(url: String) = Unit
99100
override fun deeplinkParsed(type: DeeplinkType?, url: String) = Unit
100101
override fun deeplinkRouted(type: DeeplinkType, error: Throwable?) = Unit
102+
override fun displayedErrorModal(title: String, message: String) = Unit
101103
}
102104

103105
@Composable

apps/flipcash/shared/analytics/src/main/kotlin/com/flipcash/app/analytics/Events.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ internal sealed interface AnalyticsEvent {
3030
)
3131
}
3232

33+
data class ErrorModalDisplayed(
34+
val title: String,
35+
val message: String
36+
): AnalyticsEvent {
37+
override val name = "Error Modal Displayed"
38+
override fun toProperties() = mapOf(
39+
"Title" to title,
40+
"Message" to message
41+
)
42+
}
43+
3344
sealed interface DeeplinkEvent : AnalyticsEvent {
3445
data class Open(val url: String) : DeeplinkEvent {
3546
override val name = "Deeplink: Open"

apps/flipcash/shared/analytics/src/main/kotlin/com/flipcash/app/analytics/internal/MixpanelAnalyticsDelegate.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ internal class MixpanelAnalyticsDelegate @Inject constructor(
216216
track(AnalyticsEvent.DeeplinkEvent.Routed(type, error))
217217
}
218218

219+
override fun displayedErrorModal(title: String, message: String) {
220+
track(AnalyticsEvent.ErrorModalDisplayed(title, message))
221+
}
222+
219223
// region Internal
220224

221225
private fun track(event: AnalyticsEvent, vararg extra: Pair<String, String>) {

libs/messaging/src/main/kotlin/com/getcode/manager/BottomBarManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ object BottomBarManager {
6060
val onClose: (selection: SelectedBottomBarAction) -> Unit = { },
6161
val onTimeout: () -> Unit = { },
6262
val type: BottomBarMessageType = BottomBarMessageType.DESTRUCTIVE,
63+
val isError: Boolean = type == BottomBarMessageType.ERROR,
6364
val isDismissible: Boolean = true,
6465
val showScrim: Boolean = true,
6566
val timeoutSeconds: Int? = null,

ui/components/src/main/kotlin/com/getcode/ui/components/bars/BottomBarContainer.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import kotlinx.coroutines.delay
6868
import kotlinx.coroutines.launch
6969

7070
@Composable
71-
fun BottomBarContainer(barMessages: BarMessages) {
71+
fun BottomBarContainer(barMessages: BarMessages, onShown: (BottomBarManager.BottomBarMessage) -> Unit = {}) {
7272
val scope = rememberCoroutineScope()
7373
val bottomBarMessage by barMessages.bottomBar.collectAsState()
7474
val bottomBarVisibleState = remember(bottomBarMessage?.id) { MutableTransitionState(false) }
@@ -177,6 +177,7 @@ fun BottomBarContainer(barMessages: BarMessages) {
177177
}
178178
BottomBarView(
179179
bottomBarMessage = bottomBarMessage,
180+
onShown = onShown,
180181
onClose = closeWith,
181182
onBackPressed = { closeWith(SelectedBottomBarAction(-1)) }
182183
)
@@ -189,11 +190,16 @@ fun BottomBarContainer(barMessages: BarMessages) {
189190
@Composable
190191
fun BottomBarView(
191192
bottomBarMessage: BottomBarManager.BottomBarMessage?,
193+
onShown: (BottomBarManager.BottomBarMessage) -> Unit,
192194
onClose: (selection: SelectedBottomBarAction) -> Unit,
193195
onBackPressed: () -> Unit
194196
) {
195197
bottomBarMessage ?: return
196198

199+
LaunchedEffect(bottomBarMessage.id) {
200+
onShown(bottomBarMessage)
201+
}
202+
197203
BackHandler(enabled = bottomBarMessage.isDismissible) {
198204
onBackPressed()
199205
}

0 commit comments

Comments
 (0)