iShaalan
iShaalan

Reputation: 789

Google Analytics iOS and Alamofire and cocoapods

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

Upvotes: 6

Views: 1061

Answers (2)

douarbou
douarbou

Reputation: 2283

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 :)..

Upvotes: 1

Fuad Kamal
Fuad Kamal

Reputation: 1182

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

Upvotes: 5

Related Questions