Google Analytics For iOS Without Cocoapods
This post serves a rather self-documenting purpose to remind me of the drudgery that I had to go through implementing such seemingly trivial stuff. I’ll be glad to share for anyone who’s in the same boat as I did.
First, I made some assumptions about you.
- You develop for iOS in Swift.
- You use Google Analytics for iOS.
- You hate cocoapods with passion for it being intrusive and unnecessarily complex. You use carthage or simple git submodule
The first problem we face is that GA for iOS is distributed through cocoapods only. And since it’s closed-source project, you have no access to source code so can’t do drag and drop source files either.
But you can still download the archive file. Go to this link and download the zip and unzip.
Now you must be wondering, this zip lacks some serious core libraries. One of these missing libraries is this.
GGLContext class basically bootstraps your app to use Google SDK all automagically using GoogleService-Info.plist, which you can download from your google developer console.
Moreover, this introduction by Google assumes you have everything set up using cocoapods.
// Configure tracker from GoogleService-Info.plist. var configureError:NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \(configureError)")
needs to be this
GAI.sharedInstance().trackerWithTrackingId("YOUR TRACKING ID")
Also in your
briding-header.h, instead of
you need to import
#import "GAI.h" #import "GAIDictionaryBuilder.h" #import "GAIFields.h" #import "GAILogger.h"
And simply drag and drop
GoogleAnalytics/Library/*.h from the zip you’ve downloaded.
That’s it. That’s all you need. Hope this helps someone who’s ripping their hair out at 1AM, searching the net for seemingly trivial task.