Ad

Using Google Analytics SDK And Firebase SDK Together

I'm having a crash on [FIRApp configure] step in my AppDelegate's didFinishLaunchingWithOptions method.

Crash gives me completely no information.

But I'm using Google Analytics SDK in my app as well. Maybe that's could be the reason?

So my question is - is it possible to use both Google Analytics and Firebase SDKs at the same time in one app?

Thanks.

Ad

Answer

I resolved my problem. For GA tracking we should use this lines of code in AppDelegate's didFinishLaunchingWithOptions method.

guard let gai = GAI.sharedInstance() else {
  assert(false, "Google Analytics not configured correctly")
}
gai.tracker(withTrackingId: "YOUR_TRACKING_ID")

For Firebase tracking we should use

FirebaseApp.configure()

in the same place. This method is the default method for the Firebase initialization in your application. It takes all the needed for init data from the GoogleService-Info.plist file which you should download from your dashboard on the Firebase. And it was crashing for me on the init step.

So the actual problem: Default GoogleService-Info.plist file don't include the TRACKING_ID field which is required for the Firebase initialization.

Solution: Just add the TRACKING_ID property to your GoogleService-Info.plist file. The value of this property should have this format: UA-XXXXXXXX-XX.

Ad
source: stackoverflow.com
Ad