Google Analytics with Firebase

I am trying to integrate Google Analytics into an iOS app. On the Google Analytics page, it is recommended to download this link (link) from Cocoapods, where the library comes with Firebase.

My question is why does Google provide Firebase with Goole analytics and what are the benefits of using Google Analytics with Firebase?

Can I download only the Google Analytics SDK and it will work with the same features?

+8
ios google-analytics
source share
3 answers

Fun fact: instead of the pod GoogleAnalytics can use the pod GoogleAnalytics (note the missing / ) if you want to install the Google Analytics module without any additional Google / Firebase guff.

+16
source share

Of course, OTT, that one cocoapod

 pod 'Google/Analytics' 

Installs all of them:

 Installing FirebaseAnalytics (3.6.0) Installing FirebaseCore (3.4.5) Installing FirebaseInstanceID (1.0.8) Installing Google (3.0.3) Installing GoogleAnalytics (3.17.0) Installing GoogleInterchangeUtilities (1.2.2) Installing GoogleSymbolUtilities (1.1.2) Installing GoogleToolboxForMac (2.1.0) 

ToolboxForMac? Firebase I just want an easy Analytics solution. Its still in Objective-C too!

Crashlytics, here I come.

+4
source share

Here I will show you how you can add Google Analytics to your iOS app to measure user activity for the named screens. If you don’t have an application yet and just want to see how Google Analytics works, check out our sample application.

Note. Starting with version 3.16 of the Google Analytics SDK for iOS, Xcode 7.3 or higher is required. Objective-C Swift

Analytics uses CocoaPods to install and manage dependencies. Open a terminal window and navigate to the location of the Xcode project for your application. If you have not created a subfile for your application, create it now:

pod init Open the subfile created for your application and add the following:

pod 'Google / Analytics' Save the file and run:

pod install This creates a .xcworkspace file for your application. Use this file for all future developments in your application.

Get configuration file

Click the button below to get the configuration file that will be added to your project.

The configuration file provides service information for your application. To get it, you must select an existing project for your application or create a new one. You also need to provide the package identifier for your application.

GET THE CONFIGURATION FILE

Add configuration file to your project

Drag the GoogleService-Info.plist file that you just uploaded to the root of your Xcode project and added it to all goals.

Initialize analytics for your application

Now that you have the configuration file for your project, you are ready to begin implementation. First set up a shared Analytics object inside AppDelegate. This allows your application to submit data to Google Analytics. You will do the following:

Include the necessary headers.

Install the Analytics tracker inside the didFinishLaunchingWithOptions file. Send exceptions and registration information (optional). To make these changes, first make sure your Swift project has a BridgingHeader. Then, inside this bridge header, add Analytics:

 #import <Google/Analytics.h> 

Finally, override the didFinishLaunchingWithOptions method to configure the GGLContext:

 // Configure tracker from GoogleService-Info.plist. var configureError:NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \(configureError)") // Optional: configure GAI options. let gai = GAI.sharedInstance() gai.trackUncaughtExceptions = true // report uncaught exceptions gai.logger.logLevel = GAILogLevel.Verbose // remove before app release AppDelegate.swift 

Add screen tracking

Here you submit a named screen view to Analytics whenever a user opens or changes screens in your application. Open the view controller that you want to track, or if it is a new application, open the default view controller. Your code should do the following:

Add required title <Google/Analytics.h>

Use the viewWillAppear method or override function to insert screen tracking. Enter a screen name and follow up.

 let tracker = GAI.sharedInstance().defaultTracker tracker.set(kGAIScreenName, value: name) let builder = GAIDictionaryBuilder.createScreenView() tracker.send(builder.build() as [NSObject : AnyObject]) ViewController.swift 

Note. . You can add a tracking code to each UIViewController that the screen represents, regardless of whether it was shown to your user imperatively (through code) or through a storyboard. Set a name inside each UIViewController if you want to distinguish between the screen views for your application in Google Analytics. All activity recorded on a common tracker sends the last screen name before replacement or cleaning (set to zero).

ViewController.swift

+1
source share

All Articles