首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么Firebase first_open事件不会自动发送,除非我第一次显式地logEvent一个虚拟事件?

为什么Firebase first_open事件不会自动发送,除非我第一次显式地logEvent一个虚拟事件?
EN

Stack Overflow用户
提问于 2022-09-04 15:00:21
回答 2查看 231关注 0票数 1

我正在跟踪安装程序https://www.raywenderlich.com/18579842-firebase-analytics-getting-started

我使用的是标志-FIRAnalyticsDebugEnabled

我在Firebase分析调试视图中查看实时结果

我还检查了XCode的控制台输出。

但是,我注意到,如果我以以下方式编写代码

没有收到任何Firebase分析事件

代码语言:javascript
运行
复制
import Firebase

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {    
        FirebaseApp.configure()
        
        return true
    }

但是,如果我用以下方式编写代码

接收Firebase分析first_open事件

代码语言:javascript
运行
复制
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事件,而不必记录虚拟事件?

EN

回答 2

Stack Overflow用户

发布于 2022-09-16 07:06:35

这是我正在使用的代码片段,以确保将first_open事件发送到Firebase控制台。

代码语言:javascript
运行
复制
@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事件。

尽管如此,我还是不知道为什么需要这样的额外代码片段。我觉得应该自动发送?

票数 0
EN

Stack Overflow用户

发布于 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

代码语言:javascript
运行
复制
@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
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73600417

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档