2

Recently I have added Firebase to my project to add event tracking. The problem is that I can not log custom events.

  • I have enabled Analytics at firebase
  • I have added the GoogleService-Info file
  • I have enabled Firebase debug flag for my scheme
  • I have implemented a class to encapsulate Firebase analytics stuff
  • I call FirebaseApp.configure() and Firebase.Analytics.setAnalyticsCollectionEnabled(true) inside my AppDelegate

This is how I log a custom event:

func log(event: AnalyticsEvent, parameters: [String: Any]? = nil) {
    Analytics.logEvent(event.rawValue, parameters: parameters)
}

This is my output:

    [FirebaseCore][I-COR000001] Configuring the default app.
    2022-06-09 13:39:44.212829+0200 Salud[29676:4134524] 9.0.0 - [FirebaseCore][I-COR000029] Attempted to register protocol FIRAnalyticsInterop, but it already has an implementation.
    2022-06-09 13:39:44.213109+0200 Salud[29676:4134524] 9.0.0 - [FirebaseCore][I-COR000029] Attempted to register protocol FIRAnalyticsInterop, but it already has an implementation.
    2022-06-09 13:39:44.213353+0200 Salud[29676:4134524] 9.0.0 - [FirebaseCore][I-COR000029] Attempted to register protocol FIRAnalyticsInterop, but it already has an implementation.
    2022-06-09 13:39:44.213620+0200 Salud[29676:4134524] 9.0.0 - [FirebaseCore][I-COR000033] Data Collection flag is not set.
    2022-06-09 13:39:44.223030+0200 Salud[29676:4134521] 9.0.0 - [FirebaseAnalytics][I-ACS024000] Debug mode is on
2022-06-09 13:39:44.620129+0200 Salud[29676:4134517] 9.0.0 - [FirebaseAnalytics][I-ACS820009] Successfully start the task manager
2022-06-09 13:39:44.275973+0200 Salud[29676:4134521] 9.0.0 - [FirebaseAnalytics][I-ACS023007] Analytics v.9.0.0 started
2022-06-09 13:39:45.168823+0200 Salud[29676:4134517] 9.0.0 - [FirebaseAnalytics][I-ACS800005] Registered client: app_measurement
2022-06-09 13:39:45.169209+0200 Salud[29676:4134517] 9.0.0 - [FirebaseAnalytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
2022-06-09 13:39:45.170439+0200 Salud[29676:4134527] 9.0.0 - [FirebaseAnalytics][I-ACS029014] Successfully parsed a configuration. Version: 1650346334627630
2022-06-09 13:39:45.170936+0200 Salud[29676:4134517] 9.0.0 - [FirebaseAnalytics][I-ACS023016] Analytics is ready to receive events
2022-06-09 13:39:45.176492+0200 Salud[29676:4134527] 9.0.0 - [FirebaseAnalytics][I-ACS032003] iAd framework is not linked. Search Ad Attribution Reporter is disabled.
2022-06-09 13:39:45.177197+0200 Salud[29676:4134527] 9.0.0 - [FirebaseAnalytics][I-ACS023024] No data to upload. Upload task will not be scheduled
2022-06-09 13:39:45.178023+0200 Salud[29676:4134521] 9.0.0 - [FirebaseAnalytics][I-ACS002002] Engagement timer scheduled to fire in approx. (s): 3600
2022-06-09 13:39:45.178231+0200 Salud[29676:4134521] 9.0.0 - [FirebaseAnalytics][I-ACS023012] Analytics collection enabled
2022-06-09 13:47:24.838692+0200 Salud[29676:4139565] 9.0.0 - [FirebaseAnalytics][I-ACS002001] APMExperimentAlarm fired
2022-06-09 13:47:24.839090+0200 Salud[29676:4139565] 9.0.0 - [FirebaseAnalytics][I-ACS002003] APMExperimentAlarm canceled
2022-06-09 13:47:24.840845+0200 Salud[29676:4139470] 9.0.0 - [FirebaseAnalytics][I-ACS002002] APMExperimentAlarm scheduled to fire in approx. (s): 14399.99764418602

Special attention to this line:

2022-06-09 13:39:44.486535+0200 Salud[29676:4134524] 9.0.0 - <AppMeasurement>[I-ACS023147] Google Analytics for Firebase has not been created. Please, configure Firebase by calling [FIRApp configure]

A default event is logged:

2022-06-09 13:54:34.059385+0200 Salud[30114:4145197] 9.0.0 - [FirebaseAnalytics][I-ACS800019] Cannot find launched flag. Returned the default flag value. SDK name, flag name, default flag: app_measurement, persistent_config_in_application_support_enabled, 0
2022-06-09 13:54:34.063803+0200 Salud[30114:4145197] 9.0.0 - [FirebaseAnalytics][I-ACS023087] User property set. Name, value: ga_session_id (_sid), 1654775672
2022-06-09 13:54:34.065824+0200 Salud[30114:4145196] 9.0.0 - [FirebaseAnalytics][I-ACS023087] User property set. Name, value: ga_session_number (_sno), 3
2022-06-09 13:54:34.068288+0200 Salud[30114:4145196] 9.0.0 - [FirebaseAnalytics][I-ACS023051] Logging event: origin, name, params: auto, session_start (_s), {
    ga_event_origin (_o) = auto;
    session_id (_sid) = 1654775672;
    session_number (_sno) = 3;
}
2022-06-09 13:54:34.089819+0200 Salud[30114:4145196] 9.0.0 - [FirebaseAnalytics][I-ACS023073] Debug mode is enabled. Marking event as debug and real-time. Event name, parameters: session_start (_s), {
    ga_debug (_dbg) = 1;
    ga_event_origin (_o) = auto;
    ga_realtime (_r) = 1;
    session_id (_sid) = 1654775672;
    session_number (_sno) = 3;
}
2022-06-09 13:54:34.096578+0200 Salud[30114:4145198] 9.0.0 - [FirebaseAnalytics][I-ACS023072] Event logged. Event name, event params: session_start (_s), {
    ga_debug (_dbg) = 1;
    ga_event_origin (_o) = auto;
    ga_realtime (_r) = 1;
    session_id (_sid) = 1654775672;
    session_number (_sno) = 3;
}

Am I missing something in order to be able to log custom events?

Also, I am not able to see Events inside Firebase Console, I this this is due to not having GoogleAnalytics permissions I guess: enter image description here

Andoni Da Silva
  • 1,161
  • 15
  • 31

1 Answers1

0

The main issue that was provoking the event lost was having two dynamic imports of firebase:

Class FIRAEvent is implemented in both /Xcode/DerivedData/Main-fnkojjbpikowkgcilxqhbtvtgjso/Build/Products/Debug-iphonesimulator/Services_FMWK.framework/Services_FMWK (0x1083e15e8) and /Xcode/DerivedData/Main-fnkojjbpikowkgcilxqhbtvtgjso/Build/Products/Debug-iphonesimulator/Common_FMWK.framework/Common_FMWK (0x10bd437b8). One of the two will be used. Which one is undefined.

In order to solve that, I have added Firebase using SPM due to it imports libs statically.

Notice that if you are using GoogleTagManaget, this lib depends on Firebase.

Answer here: https://stackoverflow.com/a/61352175/6655691

Andoni Da Silva
  • 1,161
  • 15
  • 31