Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After implementing Google Analytics according to documentation, I am getting an Use Of Unresolved Identifier 'GGLContext' Error

I have implemented the Google Mobile Analytics according to steps outlined on the Google Documentation Page. I have added the pod, I have the bridging header in place, I have downloaded the configuration file and imported the plist file provided. However, when I insert the following code into my appDelegate file, I get the error Use of Unresolved Identifier 'GGLContext'.

        // Configure tracker from GoogleService-Info.plist.
    var configureError:NSError?
    GGLContext.sharedInstance().configureWithError(&configureError)
    assert(configureError == nil, "Error configuring Google services: \(configureError)")

    // Optional: configure GAI options.
    var gai = GAI.sharedInstance()
    gai.trackUncaughtExceptions = true  // report uncaught exceptions
    gai.logger.logLevel = GAILogLevel.Verbose  // remove before app release

I have searched many forums and cannot find any solution. I have even run pod try Google and looked at their example project and cannot see a difference. Has any experienced this before (XCode 6.4, OSX 10.10.5, Swift 1)?

like image 473
Craig.Pearce Avatar asked Nov 02 '15 20:11

Craig.Pearce


3 Answers

Don't use CGLContext try to implement it manually with your Google Analytic ID.

I find this more reliable, as I also try to do it the Google documented way that didn't work for me as well, I believe they have to update their context (I believe this is due to swift 2 - Update).

Example: enter this in your AppDelegate.swift within didFinishLaunchingWithOptions: method.

// Init GAI.
let Tracker = GAI.sharedInstance()

//Add Publisher Track ID
Tracker.trackerWithTrackingId("UA-XXXXXXXXX-X")

Please ask if you have any other question you would like to manually implement (trackUncaughtExceptions, logger etc)

UPDATE:

Your bridge header file should look something as following, you should add whichever feat you're using in Google Analytic Framework.

//Google Analytics
#import "GAI.h"
#import "GAITracker.h"
#import "GAIFields.h"
#import "GAIDictionaryBuilder.h"

Here is a screenshot of available classes.

enter image description here

like image 89
Brian Nezhad Avatar answered Nov 07 '22 11:11

Brian Nezhad


just do this

pod 'Google/Analytics'

and

pod install

create -Bridging-Header.h in your project root.

and then copy that to .h file

  #import <Google/Analytics.h>

and drag and drop GoogleService-Info.pist to root of project.

this is so important. go to build setting and find swift compiler-code Generation and then set $(SWIFT_MODULE_NAME)-Bridging-Header.h to Objective-C Bridging Header

clean project and build and then run.

like image 34
idris yıldız Avatar answered Nov 07 '22 11:11

idris yıldız


At the point in time the 'Google/Analytics' pod doesn't support Bitcode, so when you go to do a production build, you will run into problems. Especially if you want to support WatchOS or tvOS.

At this point in time, using the "GoogleAnalytics" pod seems to be the best option, and setting up the tracker manually with

// Init GAI.
let Tracker = GAI.sharedInstance()

//Add Publisher Track ID
Tracker.trackerWithTrackingId("UA-XXXXXXXXX-X")

You can also go to https://code.google.com/p/analytics-issues/issues/detail?id=671 and scroll to the bottom to vote for Google to fix the recommended path to work with Bitcode.

like image 41
Dave Koziol Avatar answered Nov 07 '22 12:11

Dave Koziol