1

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
  • Just curious, why follow the Ray Wenderlich tutorial and not the official Firebase Analytics tutorial?
    – slushy
    Commented Sep 4, 2022 at 16:12
  • I always find Ray Wenderlich tutorial is easy to understand, and reasonable good. Commented Sep 16, 2022 at 7:01

2 Answers 2

0

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?

1
  • I'm under the impression that you may have temporarily disabled your data collection for Analytics. To re-enable collection, you would need to call the setAnalyticsCollectionEnabled() method of the FirebaseAnalytics class.
    – dani
    Commented Jan 5, 2023 at 15:17
0

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
    }

Not the answer you're looking for? Browse other questions tagged or ask your own question.