skip to Main Content

I am following the setup https://www.raywenderlich.com/18579842-firebase-analytics-getting-started

I am using flag -FIRAnalyticsDebugEnabled

I view the real-time result in Firebase Analytics Debug View

I also check the console output of XCode.

However, I notice that, if I write my code in the following way

Not receiving any Firebase analytics event

import Firebase

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

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

But, if I write the code in the following way

Receiving Firebase analytics first_open event

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
    }

I need to logEvent a dummy event explicitly, in order to receive first_open.

May I know why is it so? Is there a way, I can still receive first_open event automatically, without having to log a dummy event?

2

Answers


  1. Chosen as BEST ANSWER

    This is the code snippet I am using, to ensure first_open event is sent to Firebase console.

    @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
        }
    

    I have verified by looking at Firebase console. The first_open event is received.

    Still, I am not sure why such extra code snippet is required. I thought it should be sent automatically?


  2. In my app I have admob ads and analytics. My assumption is that because of admob sdk, analytics stops working. This is certainly a bug.

    Solution:
    You will have to request iOS ATT alert or UMP consent from Google.
    I prefer UMP sdk because it solves ATT alert and GDPR.
    UMP sdk: https://developers.google.com/admob/ump/ios/quick-start
    How it works: 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
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search