Error configuring Google analytics for iOS app with GoogleService-Info.plist
Asked Answered
W

2

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.

Waterhouse answered 10/7, 2015 at 6:22 Comment(6)
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 thisMisspeak
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.Waterhouse
try this link may be help with youMisspeak
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.Waterhouse
are you use the cocoa pods for analyticsMisspeak
Please see this answer: #31294880 for various solutions to this issue, e.g. check build phases....Meave
T
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!

Telegraph answered 23/9, 2015 at 16:21 Comment(0)
S
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.

Shantishantung answered 4/2, 2016 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.