How are people sending screen_view analytics to Fi...
# compose
d
How are people sending screen_view analytics to Firebase from their Compose code? Which side effect function do you use? I'm trying to find how to match SwiftUI's
onAppear
which runs on navigating to and back to a screen but does not run on background and foregrounding the app...
The official iOS Firebase sdk provides a utility modifier to trigger screen view analytics: https://github.com/firebase/firebase-ios-sdk/blob/04a2b57ca6b957863ab1267423b1365e1e8587d7/FirebaseAnalytics/Sources/Analytics%2BSwiftUI.swift#L34 evidently, it uses
onAppear
internally
However I can't find a matching side effect function in Compose -
LaunchedEffect
also triggers when you background and foreground the app, which
onAppear
does not do
perhaps
Copy code
LifecycleEventEffect(Lifecycle.Event.ON_CREATE) {

}
would do the trick? Has anyone else done screen_view analytics this way?
n
Use https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/package-summary#(androidx.compose.ui.Modifi[…]undsHolder,kotlin.Function1) The callback will be called when the view enters/exits the screen on a scroll or on a navigation, but will NOT be called on background/foreground.