0

I want to use TWO Firebase Analytics for one single app, one single code.

Project 1: Firebase Analytics Test Project Project 2: Firebase Analytics Prod Project

How can I add two google-services.json file in one single project. Is there any other way to use the same.

Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143

1 Answers1

3

Analytics works with only 1 Google App ID in your GoogleService-Info.plist. There is no way to send traffic to both projects. I'd recommend to have 2 separate projects for test and release versions. It's not recommended to mix up Test data with Production data as it is confusing and Production data may not reflect the real behaviors if test data is in it. For example, if you run Test app every night by installing and uninstalling, it may appear that you have a new user every day in your production app.

One thing you can do is having a GoogleService-Info.plist for the release but use the run-time APIs to use the custom FIROptions

-[FIROptions initWithContentsOfFile:(NSString *)plistPath] 

where plistPath is the path to the custom GoogleService-Info.plist, say CustomGoogleService-Info.plist. Or

- (instancetype)initWithGoogleAppID:(NSString *)googleAppID
                           bundleID:(NSString *)bundleID
                        GCMSenderID:(NSString *)GCMSenderID
                             APIKey:(NSString *)APIKey
                           clientID:(NSString *)clientID
                         trackingID:(NSString *)trackingID
                    androidClientID:(NSString *)androidClientID
                        databaseURL:(NSString *)databaseURL
                      storageBucket:(NSString *)storageBucket
                  deepLinkURLScheme:(NSString *)deepLinkURLScheme;

In this way, you can put it under the compiler flag for testing version. In the release, the compiler flag will remove that line and use the correct GoogleService-Info.plist for the release version. For example:

#ifdef TESTING    
FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:pathToCustomPlist];
[FIRApp configureWithOptions:options];
#endif // TESTING
adbitx
  • 2,019
  • 8
  • 13