5

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?

John D.
  • 2,521
  • 3
  • 24
  • 45

2 Answers2

8

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.

MickeDG
  • 404
  • 5
  • 18
  • I can confirm this works when combining with this answer http://stackoverflow.com/a/24112024/1359306. I used swift and set `trackUncaughtExceptions` to true, `trackerWithTrackingId`, and `dispatchInterval`. – Patrick Mar 14 '16 at 23:38
  • Thanks so much for this suggestion! I dont know why the documentation doesn't even mention this method! I was trying to swap plist files with a run script in the build phase until I found this option! – Nitin Alabur Sep 14 '16 at 20:31
  • Confirm still works in 2017! Annoying though however that this is not documented and also only able to set the one field from the plist, clientID, API_KEY etc can not be set, though for me all I needed was tracking and setting the trackingID seems sufficient. – ssh88 Apr 11 '17 at 13:06
  • 1
    is there a way to do the same thing in swift ? – Hubert Solecki Sep 21 '17 at 11:39
0

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 :)

dan_fides
  • 324
  • 1
  • 10