I have been working with google analytics
fine for the past year and now I am switching to swift
. I have a problem importing it using the pods
[ I have done an extensive search and it seems a problem with [use_frameworks!] that is required by Alamofire
.
I have added the SDK manually, that is libGoogleAnalyticsServices.a
and imported some other files in a bridging file called header-Bridging-Header.h
:
#import <Google/Analytics.h>
#import <libGoogleAnalyticsServices.a>
#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIEcommerceFields.h"
#import "GAIEcommerceProduct.h"
#import "GAIEcommerceProductAction.h"
#import "GAIEcommercePromotion.h"
#import "GAIFields.h"
#import "GAILogger.h"
#import "GAITrackedViewController.h"
#import "GAITracker.h"
now in AppDelegate.swift
I am trying to configure tracker from GoogleService-Info.plist.
var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
if configureError != nil {
println("Error configuring the Google context: \(configureError)")
}
but it shows an error used of unresolved identifier GGLContext
Google was a bit slow to properly support Cocopods but this has been resolved, now. The tricky bit now is to know which version of Google Analytics pod to use as there are at least three different ones, two of which are authored by Google themselves. For using GA using CocoaPods most likely you should be using the one they officially recommend using, which is listed here: https://developers.google.com/analytics/devguides/collection/ios/v3/?ver=swift
as of this writing the pod is pod 'Google/Analytics' - using this GA should work without additional effort and without directly embedding any libraries into your code. Additionally the only thing you need in you bridging header is this:
#import <Google/Analytics.h>
For a detailed explanation of why there are so may different pods and which one to use, see this video: https://www.youtube.com/watch?v=JQJd7qyWh5k
into your cocoapods you need to set:
pod 'Google/Analytics'
If you want to use:
var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
if configureError != nil {
println("Error configuring the Google context: \(configureError)")
}
If you use:
pod 'GoogleAnalytics' #(without '/')
GGLContext will not be available :)..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With