When it comes to picking an analytics package for your mobile application, you have plenty of candidates to choose from: Google Firebase, Fabric and HockeyApp, just to name a few.
These solutions vary in price and capabilities. However, the most important consideration for many clients is interoperability with existing analytics or business intelligence packages. For this reason, we often get requests to integrate the Google Analytics Software Development Kit (SDK) into iOS and Android apps. If a mobile app’s structure hews closely to an existing website, the ability to use the same analytics suite for both allows us to easily unify reporting.
Google recently reorganized its CocoaPods offerings, moving components like its analytics package back into its own pod and deprecating the “Google” pod in the process.
It would have been a good time to redo the integration docs as well, but unfortunately, they’re still outdated and incomplete.
I'd like to quickly go over how I incorporate Google Analytics into iOS apps.
First, add the tracking ID to your info.plist.
Next, add pod to your Podfile, run pod update and then add the necessary includes to your bridging header file.
The existing docs tell you to guard against misconfiguration like this:
Unfortunately, this will break as soon as you do a release build, since assertions are removed in release configurations, and a guard block must end execution of the current scope. Here's a better solution:
You still get the assertion helping you while debugging, without running into problems later.
Next, you'll want to do some basic configuration.
When you first start integration, I recommend setting the log level to verbose. You could even use schemes or your build configurations to set it to different values as needed.
Similarly, I wouldn't change the dispatchInterval from the default unless you're actively working on your analytics code and need events to show up quicker in the reporting dashboard.
If you want Google Analytics to record uncaught exceptions, you can enable this feature here. However, be aware this will interfere with other crash reporting libraries such as Crashlytics. If you use one of them or another library that registers exception handlers, set trackUncaughtExceptions to false or initialize them after Google Analytics so the exception handler can be reset.
That should cover the basics, but I've also included an Analytics helper struct below. It's similar to what I use in my apps. Using enums for actions and screen names helps prevent typos from creeping in.
Feedback is an important part of every project. It helps you shape and evolve your product into something your users won't want to do without. Google Analytics allow you to establish a baseline for feedback that doesn't require much maintenance, so you can focus on the more important task: making sense of the data and deciding how to act on it.
This article originally appeared on Sept. 12, 2017.