I tried to find informations about how to use Google Analytics with Swift 3, and even if it looks like some people succeeded, I can't make it work myself.
The Google Analytics documentation doesn't help, it's only for working for Swift 2.
I used the pod "Google/Analytics" in version 3.17.0 and tried to add this line inside a bridging header file as some people mentioned :
#import <Google/Analytics.h>
But I got an error about Xcode complaining that bridging headers doesn't work with Swift 3.
Then I tried to add the same line inside the .h as another post suggest, but doesn't work neither, Xcode complains "Include of non-modular header inside framework module XXX".
I tried to set "Allow Non-modular Includes in Framework Modules to YES but it doesn't change anything, still got the same error.
Last thing I tried is to add :
import Google
Inside the file where I use Google Analytics, but now GAI is not recognized.
// 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.
guard let gai = GAI.sharedInstance() else {
assert(false, "Google Analytics not configured correctly")
}
gai.trackUncaughtExceptions = true // report uncaught exceptions
gai.logger.logLevel = GAILogLevel.verbose // remove before app release
Any suggestions ?
Follow these steps in order to configure Google Analytics
Create a Bridging file in your project if there is already one exists then no need to recreate it.
5.1. To create a bridging file the easiest way is to add/create new objective-c class to the project and the option pops up which ask you to create a bridging file and it sets all of the setting by default.
" #import <Google/Analytics.h> "
Open "AppDelegate.swift" and copy and paste the below code in didFinishLaunchingWithOptions for setting the Analytics tracker
// 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. guard let gai = GAI.sharedInstance() else { assert(false, "Google Analytics not configured correctly") } gai.trackUncaughtExceptions = true // report uncaught exceptions gai.logger.logLevel = GAILogLevel.verbose // remove before app release
Build your project.
I hope it works if there is any problem then let me know.