Sunil Targe Sunil Targe - 3 months ago 38
Swift Question

How to implement Firebase Google Analytics in custom keyboard?

I want to implement Firebase google analytics in my custom keyboard for button click event.

Anyone please tell me how I can do this in swift.

Answer

Add firebase sdk and GoogleService-Info.plist file to keyboard extension target. Import firebase and configure it. FIRApp.configure() must be called only once per session:

import Firebase

class FirebaseConfigurator: NSObject {
static var onceToken: dispatch_once_t = 0

static func configure() {
    dispatch_once(&onceToken) {
        FIRApp.configure()
    }
}

and

FirebaseConfigurator.configure()
FIRAnalytics.logEventWithName("button click event", parameters: nil).