Use Google Analytics for iOS without .plist file

こ雲淡風輕ζ 提交于 2019-12-10 14:40:08

问题


According to Google's documentation (Analytics for iOS), they want you to download some auto-generated .plist file to configure your app. Unfortunately, I have multiple report suites (Debug, Release) and need to switch dynamically depending on the build. So I'm trying to do one of two things:

  1. Is there a way to totally ditch the .plist file and set all the configs dynamically? What values would one need?

-OR-

  1. Can I alter the values in the Google .plist file to use variables from my project's User-Defined Build Settings? I tried adding one named GOOGLE_ANALYTICS_ID and referencing it by ${GOOGLE_ANALYTICS_ID} in the Google .plist file, but it doesn't substitute the value like how I would expect it to.

How have you dynamically instructed your app to send to different report suites depending on whether your app is Debug or Release?


回答1:


You should be able to ditch the .plist file and setting it up like so:

#import "GAI.h"
...
GAI *gai = [GAI sharedInstance];
[gai trackerWithTrackingId:@"your GA id"];
gai.trackUncaughtExceptions = YES;  // optional
gai.logger.logLevel = kGAILogLevelVerbose;  // optional - remove for release

Don't use the GGLContext stuff since that's trying to get parameters from the -plist file.




回答2:


Run into the same issue. My solution was to create separate build targets for QA and production, use pre-processor macros for target specific settings in code and 2 separate plist files for stuff like facebook app ID, bundle IDs (you can specify which plist file build target is using on Info tab of the project settings).

Same thing with GA - 2 plist files for each target, and to avoid naming conflict (because if you change plist name from GoogleService-Info, the app will crash) - simply put your QA plist in separate folder, it will still work just fine from there.

Don't mess with target memberships for you plists :)



来源:https://stackoverflow.com/questions/33403604/use-google-analytics-for-ios-without-plist-file

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