我正在跟踪安装程序https://www.raywenderlich.com/18579842-firebase-analytics-getting-started
我使用的是标志-FIRAnalyticsDebugEnabled
我在Firebase分析调试视图中查看实时结果
我还检查了XCode的控制台输出。
但是,我注意到,如果我以以下方式编写代码
没有收到任何Firebase分析事件
import Firebase
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
return true
}
但是,如果我用以下方式编写代码
接收Firebase分析first_open事件
import Firebase
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
let title = "xxx"
Analytics.logEvent(AnalyticsEventSelectContent, parameters: [
AnalyticsParameterItemID: "id-\(title)",
AnalyticsParameterItemName: title,
AnalyticsParameterContentType: "cont",
])
return true
}
我需要显式地logEvent一个虚拟事件,以便接收first_open
。
我能知道为什么会这样吗?有没有办法,我仍然可以自动接收first_open
事件,而不必记录虚拟事件?
发布于 2022-09-16 07:06:35
这是我正在使用的代码片段,以确保将first_open
事件发送到Firebase控制台。
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
FirebaseApp.configure()
// Not sure why. We need to call this function for first_open to be sent automatically.
// https://stackoverflow.com/questions/73600417/why-firebase-analytics-first-open-event-is-not-sent-automatically-unless-i-first
Analytics.setAnalyticsCollectionEnabled(true)
return true
}
我已经通过查看Firebase控制台进行了验证。接收到first_open
事件。
尽管如此,我还是不知道为什么需要这样的额外代码片段。我觉得应该自动发送?
发布于 2022-10-04 21:13:52
在我的应用程序中,我有admob广告和分析。我的假设是,由于admob,分析停止工作。这当然是个bug。
解决方案:您必须向谷歌请求iOS ATT警报或UMP同意。我更喜欢UMP,因为它解决了ATT警报和GDPR问题。UMP:https://developers.google.com/admob/ump/ios/quick-start是如何工作的:https://support.google.com/admob/answer/10115027
@main
struct MyApp: App {
init() {
FirebaseApp.configure()
Analytics.setAnalyticsCollectionEnabled(true) //this is explicitly needed
showConsent()
}
var body: some Scene {
WindowGroup {
RouterView()
}
}
private func showConsent() {
//request UMP consent or IDFA consent
}
https://stackoverflow.com/questions/73600417
复制相似问题