I recently installed Firebase Analytics in my SwiftUI app. Everything works great except the automatic screen views. Am I obligated to call AnalyticsEventScreenView for every view I would like to track?
Firebase 9.0.0 has introduced new APIs that are specific to SwiftUI and have exited beta. There is now a View extension that implements a ViewModifier that provides you some functionality:
func analyticsScreen(name: String,
class: String = "View",
extraParameters: [String: Any] = [:])
Analytics+SwiftUI.swift
For example:
struct MyView: View {
var body: some View {
Text("Hey")
.analyticsScreen(
name: "Screen Name",
extraParameters: [
AnalyticsParameterScreenName: "\(type(of: self))",
AnalyticsParameterScreenClass: "\(type(of: self))"
]
)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With