Search code examples
iosswiftfirebasecustom-keyboardfirebase-analytics

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.


Solution

  • 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).