Firebase Analytics (Two projects) for single app

对着背影说爱祢 提交于 2019-12-12 03:58:48

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/43761824/firebase-analytics-two-projects-for-single-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!