5

I followed this Google developer guide to add Google analytics to an iOS app using Cocoa Pods. I added the GoogleService-Info.plist and put the initialisation code in didFinishLaunchingWithOptions. The app builds fine, but then crashes at the point it tries to initialise GA. Specifically these lines of code:

NSError *configureError;
[[GGLContext sharedInstance] configureWithError:&configureError];
NSAssert(!configureError, @"Error configuring Google services: %@", configureError);

The assert statement is failing and the output in the console is:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'Error configuring Google services: 
Error Domain=com.google.greenhouse Code=-200 "Unable to configure GGL."
{NSLocalizedFailureReason=Unable to parse supplied GoogleService-Info.plist. See log for details., 
NSLocalizedRecoverySuggestion=Check formatting and location of GoogleService-Info.plist., 
NSLocalizedDescription=Unable to configure GGL.}'

I can see this is due to the GoogleService-Info.plist file and after some investigation I found that even if I delete GoogleService-Info.plist I get the error, which leads me to believe that I had not added the file to the project correctly.

Here is a screenshot of what I checked when adding the file:

enter image description here

So I have made sure that it is added to all targets and that the file is in the root directory of the project, alongside the xcodeproj and xcworkspace files, as per the instructions on the Google developer guide.

I should also mention that this is a SpriteBuilder project, but I don't think that has anything to do with this. Also this was the first Cocoa Pod that I added, but all seems fine with that as the project builds and can find all the Google headers it needs.

Choc13
  • 796
  • 7
  • 23
  • initially tell that what is the purpose to use **GoogleService-Info.plist** in your app no need of this, if you use in analytics only you no need this – Anbu.Karthik Jul 10 '15 at 06:37
  • Sorry I don't understand what you're saying. The Google Analytics library is expecting this file to be in the project. It looks for it when `[[GGLContext sharedInstance] configureWithError:&configureError];` is called. The guide I followed created this file for me to download and explicitly instructs me to add it to the project. It's a properties file containing the `TRACKING_ID` for the GA account. – Choc13 Jul 10 '15 at 06:44
  • try this [link](http://www.raywenderlich.com/53459/google-analytics-ios) may be help with you – Anbu.Karthik Jul 10 '15 at 06:56
  • Yes I've already tried that link, but he doesn't use the Cocoa Pods method to add the Google Analytics library. So I don't believe it is configured the same way. – Choc13 Jul 12 '15 at 17:32
  • are you use the cocoa pods for analytics – Anbu.Karthik Jul 13 '15 at 03:55
  • Please see this answer: http://stackoverflow.com/questions/31294380/unable-to-find-googleservice-info-plist-while-trying-to-integrate-google-sign for various solutions to this issue, e.g. check build phases.... – class Aug 05 '15 at 20:33

2 Answers2

7

I was also stuck with this strange piece of code. But you don't need it! Just remove configureWithError and all these things.

All you need is:

[[GAI sharedInstance] trackerWithTrackingId:@"UA-11111111-2"];
[GAI sharedInstance].trackUncaughtExceptions = YES;

Somewhere inside didFinishLaunchingWithOptions. (It's from the previous GA version, right?) So, that's it! Then, do anything you want in your app:

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:@"start screen"];
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];

My Podfile looks like this:

source 'https://github.com/CocoaPods/Specs.git'

pod 'Google/Analytics', '~> 1.0.0'

It works!

Dmitry Isaev
  • 3,888
  • 2
  • 37
  • 49
0

If you already integrate google signIn it provide plist for accessing the login service detail of your app. It means when you try to integrate the analytic you dont need to add the new GoogleService-Info.plist. You just add the following keys which are missing in the existing plist file.

jaskiratjd
  • 729
  • 1
  • 6
  • 16