Home > iOS Development > GANHelpers: A helper class for using Google Analytics in iOS apps

GANHelpers: A helper class for using Google Analytics in iOS apps

Google Analytics is a full-featured, enterprise-class web analytics service from Google for tracking web and mobile application usage statistics. It’s a good idea to track how your customers use your app. There are many benefits of knowing how your app is actually being used. You can optimize some parts of your application, make decisions on adding, dropping or improving a feature or make modifications in UI to improve the usability of your app. You don’t want to work on a feature that nobody actually uses, right?

 

Google Analytics

Google Analytics

 

Google provides a simple and easy-to-use SDK for integrating Google Analytics in iOS apps. It almost enables you to do everything you can do with the Google Analytics javascript interface. Latest version of the SDK can be found here and you can find instructions on how to add the SDK to your project here.

GANHelpers is an objective-c class with some utility methods for accessing Google Analytics functions such as trackPageView and trackEvent. In order to use it, add Google Analytics iOS SDK to your project. Also add GANHelpers.h and .m files to your project. Don’t forget to link with CFNetwork.framework and libsqlite because Google Analytics iOS SDK needs them.

First, configure GANHelpers by setting your app’s Google Analytics profile id in GANHelpers.m:

 

In your project’s AppDelegate start the tracker:

 

Everytime your view controllers appear, you can track them as page views:

 

You can track any UI actions you want with trackEvent:

 

Get the source code at GitHub: https://github.com/ardalahmet/GANHelpersDemo

For more detailed information about tracking methods and Google Analytics in general check Google Analytics Developer Docs.