Will Firebase Analytics work from the simulator in Xcode?
Asked Answered
L

3

10

In an IOS app I have

enter image description here

and I ensured the plist "defeat" entry is not there, and then I have analytics events like

 Analytics.logEvent("touchedButton", parameters: nil)

In fact, if I run the app just in the Xcode simulator .. are these events reported to Firebase Analytics and show up?

Or perhaps if you build to an iPhone?

Or does it only work if it's an actual build which has gone through TestFlight?

Surprisingly I couldn't find this info anywhere.

Is it precisely here that such custom events will show:

enter image description here

Lobell answered 23/7, 2018 at 18:47 Comment(0)
F
16

Yes, both simulator or device will work.

If you haven't already read, read their getting started tutorials, it covers most of it https://firebase.google.com/docs/analytics/ios/start

A couple of points

  1. Make sure when you configure your Firestore settings , you enable analytics

AnalyticsConfiguration.shared().setAnalyticsCollectionEnabled(true)

I do all of this initial settings in AppDelegate

something like

//init Firebase
        FirebaseConfiguration.shared.setLoggerLevel(.min)
        FirebaseApp.configure()
        Fabric.with([Crashlytics.self])
        let _ = FirebaseConfig.sharedInstance // This is a custom singelton class where I enable the analytics
  1. In Scheme settings for your target you need to add -FIRAnalyticsDebugEnabled

enter image description here

As you can see I have also a disable option there, sometimes analytics goes crazy and spams the console , so I'd like to disable it with . -FIRDebugDisabled

  1. Analytics clusters your events unless you specify it is a custom event.

For example I use following to tag the viewcontroller names

    func logEvent(eventTitle:String , eventContent:String)
{
    Analytics.logEvent(AnalyticsEventSelectContent, parameters: [
        AnalyticsParameterItemID: "AppName-\(eventTitle)" as NSObject,
        AnalyticsParameterItemName: eventTitle as NSObject,
        AnalyticsParameterContentType: eventContent as NSObject
        ])
}

But int the firestore these are clustered under select_content section because I used AnalyticsEventSelectContent key when creating the log.

Under main events screen , select_content my view controlers logged with above function enter image description here

4.There is a specific DebugView in the FirestoreConsole that works with a device, it updates every 60 seconds as long as settings for -FIRAnalyticsDebugEnabled is true in the scheme.

enter image description here

  1. There is a significant delay in the Event Section of Firestore console, I don't know why this happens, but sometimes there is a delay up to 15 - 30 mins. Havent researched that issue yet, it really doesnt bother me.
Fennessy answered 23/7, 2018 at 20:28 Comment(4)
thanks for this FANTASTIC information. I am working through it!Lobell
One thing that confuses me, say i DO NOT set " -FIRAnalyticsDebugEnabled". In fact, surely it should all still work, right? Or you mean, you must set that - for it to work in Simulator? I've just built one through to a TestFlight build on devices: surely, it will work then even if " -FIRAnalyticsDebugEnabled" is NOT set? What do you reckon ?Lobell
I think that setting is mostly for DebugView in firestore console. I haven't tested it with a simulator but my UI tests sends logevents, so I assume it works with simulator.....Your testflight builds should still work because I had my -FIRAnalyticsDebugEnabled off in the scheme settings and I can see the events coming from my QA via my AdHoc builds. I personally find it annoying that if I leave -FIRAnalyticsDebugEnabled , Xcode's console gets flooded with Analytics logs and I can't really find what I am actually looking for.Fennessy
I am using react-native-firebase and just adding -FIRAnalyticsDebugEnabled in the Debug scheme is enough to see logs in the DebugView while running on the iOS simulator. I dindn't need to touch AppDelegate.mDinka
C
2

Just follow https://firebase.google.com/docs/analytics/ios/start

To enable Analytics Debug mode on your development device, specify the following command line argument in Xcode :

-FIRDebugEnabled

It works perfectly for Simulator and device.

Note: For react-native debugging, launch app from xcode with the selected scheme and not with 'yarn ios', then it works perfectly for Simulator also

Champion answered 2/3, 2021 at 14:14 Comment(0)
E
0

In some cases you just need to restart the app. For example I had all setup correctly done, but it just worked when I ran it again using a different method, like XCode debug build

Eulalie answered 8/7 at 23:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.