Home » How to build » Google analytics sdk for ios v2 (legacy) – overview

Google analytics sdk for ios v2 (legacy) – overview

Google Analytics SDK for iOS v2 (Legacy) – Overview

The Google Analytics SDK for iOS makes it easy for developers to collect user engagement data form their apps. This document will provide an overview of the value of the SDK as well as a guide to getting started measuring your app using a single property ID and EasyTracker.

Introduction

The Google Analytics SDK for iOS makes it easy for developers to collect user engagement data from their apps. Developers can then use Google Analytics reports to measure:

Before you Begin

Getting Started

There are three steps to getting started with the SDK:

After completing these steps, you’ll be able to measure the following with Google Analytics:

  • App installations
  • Active users and demographics
  • Screens and user engagement
  • Crashes and exceptions

1. Adding header files and configuring your project

Download the Google Analytics for iOS SDK and add these files from the SDK package to your app:

  • GAI.h
  • GAITracker.h
  • GAITrackedViewController.h
  • GAITransaction.h
  • GAITransactionItem.h
  • libGoogleAnalytics.a

The Google Analytics SDK uses the CoreData and SystemConfiguration frameworks, so you will need to add the following to your application target’s linked libraries:

  • libGoogleAnalytics.a
  • CoreData.framework
  • SystemConfiguration.framework

If your app uses the CoreData framework: responding to a notification, e.g. NSManagedObjectContextDidSaveNotification. from the Google Analytics CoreData object may result in an exception. Instead, Apple recommends filtering CoreData notifications by specifying the managed object context as a parameter to your listener. Learn more from Apple .

2. Initializing the tracker

To initialize the tracker, import the GAI.h header in your application delegate .m file and add this code to your application delegate’s application:didFinishLaunchingWithOptions: method:

Note: When you obtain a tracker for a given tracking ID, the tracker instance is persisted in the library. When you call trackerWithTrackingId: with the same tracking ID later, the same tracker instance will be returned. Also, the Google Analytics SDK exposes a default tracker instance that gets set to the first tracker instance created. It can be accessed by:

Note that in the above example, “UA-YOUR-TRACKING-ID” here is a placeholder for the tracking ID assigned to you when you created your Google Analytics app view (profile). If you are only using one tracking ID in your app, using the default tracker method is best.

3. Implementing screen measurement

To automatically measure views in your app, have your view controllers extend GAITrackedViewController. a convenience class that extends UIViewController. and provide the view name to give to each view controller in your reports. Each time that view is loaded, a screen view will be sent to Google Analytics.

For example, suppose you have an “About” view that you want to measure with a view controller header that looks like this:

You would update this header to say:

You must also provide the view name to be used in your Google Analytics reports. A good place to put this is the view controller’s initializer method, if you have one, or the viewDidAppear: method:

As long as trackedViewName is set before sendView: is called, automatic screen measurement will take place. Whenever the view appears, a call to sendView: with the provided view name will be generated.

To learn more about screen measurement, see the Screens Developer Guide .

Congratulations! Your app is now setup to send data to Google Analytics.

Next steps

You can do much more with Google Analytics, including measuring campaigns, in-app payments and transactions, and user interaction events. See the following developer guides to learn how to add these features to your implementation:

  • Advanced Configuration – Learn more about advanced configuration options, including using multiple trackers.
  • Measuring Campaigns – Learn how to implement campaign measurement to understand which channels and campaigns are driving app installs.
  • Measuring Events – Learn how to measure user engagement with interactive content like buttons, videos, and other media using Events.
  • Measuring In-App Payments – Learn how to measure in-app payments and transactions.
  • User timings – Learn how to measure user timings in your app to measure load times, engagement with media, and more.

Если не указано иное, содержание этой страницы доступно по лицензии Creative Commons Attribution 3.0. а примеры кода – по лицензии Apache 2.0. Подробную информацию можно найти в правилах сайта .

Check out this article