Menu

How To Add Google Analytics In iOS App?

Gordon Choi
Gordon Choi
Author

iOS

Let’s implement the Google Analytics SDK onto your iOS app.

.xcworkspace

The iOS SDK implementation assumes your app’s source code is written in Objective-C and you use CocoaPods to install and manage dependencies.

Open a terminal window and navigate to the location of the Xcode project for your application. Create a Podfile for your application if it doesn’t exist.

pod init

Open the Podfile and add the following:

pod 'Google/Analytics'

Save the Podfile and run:

pod install

A .xcworkspace file will be created for your application.

Configuration file

Download the configuration file.

https://developers.google.com/mobile/add?platform=ios&cntapi=analytics&cnturl=https:%2F%2Fdevelopers.google.com%2Fanalytics%2Fdevguides%2Fcollection%2Fios%2Fv3%2Fapp%3Fconfigured%3Dtrue%23add%2Dconfig&cntlbl=Continue%20Adding%20Analytics

Drag the GoogleService-Info.plist file (i.e. configuration file) into the root of your Xcode project and add it to all targets.

AppDelegate.m

Add this to the AppDelegate.m file:

#import <Google/Analytics.h>

To configure GGLContext, override the didFinishLaunchingWithOptions method:

NSError *configureError;
[[GGLContext sharedInstance] configureWithError:&configureError];
NSAssert(!configureError, @"Error configuring Google services: %@", configureError);

GAI *gai = [GAI sharedInstance];
gai.trackUncaughtExceptions = YES;  // report uncaught exceptions
gai.logger.logLevel = kGAILogLevelVerbose;  // remove before app release

ViewController.m

Let’s add the tracker to track screen views in your iOS View Controller.

In ViewController.m, add the <Google/Analytics.h> header. Use a viewWillAppear method or function override to insert screen tracking. Give the screen a name and execute tracking.

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:name];
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];

Previous Chapters

Next Chapters





Content on Gordon Choi’s Analytics Book is licensed under the CC Attribution-Noncommercial 4.0 International license.

Gordon Choi’s Other Books:
The China Mobile SEO Book
Mobile Website Book



How To Install Google Analytics on WordPress?

Setup Guide for WordPress websites: Set up Google Analytics on WordPress website to track/measure user behavior data. Optimize your website & traffic/marketing strategies based on GA reports.

How To Install Google Analytics on Shopify?

Setup Guide of Google Analytics on Shopify websites and/or online stores: Track the behavior of your Shopify website visitors. Improve your digital marketing campaigns based on the measured data.

Google Ads (AdWords) Setup & Optimization Checklist

Setup Guide of Google Ads (AdWords): After installing analytics, get people to visit your website through Google Ads. Optimize Google Ads in 2 phases: One-time setup & ongoing optimization. Build ad campaigns that can always return highest sales with lowest cost.

Copyright 2016-2020 www.AnalyticsBook.org