2

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.

3
  • I'm voting to close this question as off-topic because this is normal as using Google Analytics. Nothing special in keyboard. Commented Aug 24, 2016 at 13:30
  • 1
    @Zaid Pathan, Normal implementation having big trouble e.g crash [reason: 'Default app has already been configured.']. So that I have asked this question. Could you please help me if you know the solution as I have described my problem in below radugrinico's answer. Commented Aug 24, 2016 at 16:46
  • Can you try calling FIRApp.configure() twice where ever you're calling? It may fix the issue. Here is something similar : stackoverflow.com/questions/37910766/… Commented Aug 24, 2016 at 18:34

1 Answer 1

4

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).
Sign up to request clarification or add additional context in comments.

4 Comments

I have done the same, but problem is when I switch my custom keyboard to native iOS keyboard and again native to custom then FIRApp.configure() method calling again and throwing **error- [reason: 'Default app has already been configured.'] ** and app crash.
@SunilTarge, you need to make sure that FIRApp.configure() is called only once per session.
yes I understood but I don't know how to calculate new session of Extension keyboard. because it doesn't have AppDelegate class.
@SunilTarge, I edited the above code. I moved FIRApp.configure() into a singleton so it will be called only once even if you call FirebaseConfigurator.configure() multiple times.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.