Google Analytics with Firebase

后端 未结 3 529
南旧
南旧 2021-01-12 00:41

I am trying to integrate Google Analytics in my iOS app. On Analytics page, Google is recommending to download (this link) with Cocoapods where library comes with Firebase.<

相关标签:
3条回答
  • 2021-01-12 00:46

    Fun fact: you can use pod GoogleAnalytics instead (note the missing /) if you wish to install the Google Analytics pod without all the extra Google/Firebase guff.

    0 讨论(0)
  • 2021-01-12 00:50

    Here I am showing you how you can add Analytics to your iOS app to measure user activity to named screens. If you don't have an application yet and just want to see how Analytics works, take a look at our sample application.

    Note: Beginning with version 3.16 of the Google Analytics for iOS SDK, 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 already created a Podfile for your application, create one now:

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

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

    pod install This creates an .xcworkspace file for your application. Use this file for all future development on your application.

    Get a configuration file

    Click the button below to get a configuration file to add to your project.

    The configuration file provides service-specific information for your app. To get it, you must select an existing project for your app or create a new one. You'll also need to provide a bundle ID for your app.

    GET A CONFIGURATION FILE

    Add the configuration file to your project

    Drag the GoogleService-Info.plist file you just downloaded into the root of your Xcode project and add it to all targets.

    Initialize Analytics for your app

    Now that you have the configuration file for your project, you're ready to begin implementing. First, configure the shared Analytics object inside AppDelegate. This makes it possible for your app to send data to Analytics. You’ll do the following:

    Include the necessary headers.

    Set the Analytics tracker inside didFinishLaunchingWithOptions. Send exceptions and logging info (optional). To do these changes, first be sure your Swift project has a BridgingHeader. Then, inside this bridging header, add Analytics:

    #import <Google/Analytics.h>
    

    Finally, override the didFinishLaunchingWithOptions method to configure 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’ll send a named screen view to Analytics whenever the user opens or changes screens on your app. Open a View Controller that you'd like to track, or if this is a new application, open the default view controller. Your code should do the following:

    Add the required header <Google/Analytics.h>

    Use a viewWillAppear method or function override to insert screen tracking. Provide a name for the screen and execute tracking.

    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 tracking code to every UIViewController that represents a screen, whether shown to your user imperatively (via code) or via storyboard. Set a name inside every UIViewController if you want to differentiate between screen views for your app in Analytics. All activity recorded on the shared tracker sends the most recent screen name until replaced or cleared (set to nil).

    ViewController.swift

    0 讨论(0)
  • 2021-01-12 00:51

    Its certainly OTT that one cocoapod

    pod 'Google/Analytics'
    

    Installs all of these:

    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 a lightweight Analytics solution. Its all still in Objective-C too!

    Crashlytics, here I come.

    0 讨论(0)
提交回复
热议问题