Sample App: A Demonstration of the Differences Between Fabric and Firebase

../../_images/apple-double.png

From left to right: Crashes/custom fields screen, and Events screen.

Overview

This Sample App is a demonstration created to highlight the key differences between implementing Crashlytics and event tracking code in a Fabric and Firebase on-boarded app.

This guide serves as a starting point for some of the ways you can incorporate practical Crashlytics and Fabric Answers/Google Analytics for Firebase events into your apps code.

Tip

We also migrated the Sample App for Android. It’s open sourced on GitHub. Depending on which folder you access, you can view the Fabric or Firebase implementation. You can also read the tutorial to build the Sample App for Android.

Getting Started

Prerequisites

To properly follow along with this guide a basic knowledge of Github, Xcode, and CocoaPods will be necessary. You will also need a Google account as well as access to the Firebase Console.

Creating a Firebase project

Firebase, Crashlytics’ new home, organizes apps in a similar way to Fabric. A Firebase project is similar to a Fabric organization.

When we on-boarded the Sample App, we created a single Firebase project that contains both the Android and iOS versions of the app. We’d recommend you do the same for your cross-platform apps to take advantage of having shared Firebase features like Realtime Database or BigQuery. However, for apps that are completely different (e.g. ChatApp and CasinoApp), we’d recommend making different projects.

Transition Options

OPTION 1: (Preferred)

We strongly recommend that you migrate with your historical Crashlytics data by visiting the migration page. After you have migrated using the migration page, please skip to step 5.

OPTION 2: Start Fresh

If you’d like to start in Firebase without your previous Fabric data, please follow these steps:

Step 1. Remove the Fabric API Key.

The Fabric API key needs to be removed from the Info.plist file in order to on-board with Firebase.

Step 2. Remove the Fabric initialization code.

We’ll first need to remove Fabric from our Xcode project settings.

  1. Start by opening your app in Xcode.
  2. Remove the Crashlytics Run Script Build Phase from your Xcode project’s Build Phases.
  3. In your AppDelegate.swift, remove your Fabric initialization code by removing the import Fabric and import Crashlytics statements, as well as any Fabric.with() statements.

Step 3: Add Firebase to your app.

To add Firebase to your app, follow along in the Firebase documentation.

Here are the code changes we’ve made so far:

--- _static/diffs/AppDelegate_01.swift
+++ _static/diffs/AppDelegate_02.swift
@@ -1,6 +1,5 @@
 import UIKit
-import Fabric
-import Crashlytics
+import Firebase
 
 @UIApplicationMain
 class AppDelegate: UIResponder, UIApplicationDelegate {
@@ -9,11 +8,11 @@
 
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
         // Developers: Welcome!
-        let welcome = "Welcome to the Sample App! Check the README for instructions."
+        let welcome = "Welcome to the Sample App. Check the README for instructions."
         assert(Bundle.main.object(forInfoDictionaryKey: "Fabric") != nil, welcome)
 
-        // Register Crashlytics, Twitter, Digits and MoPub with Fabric.
-        Fabric.with([Crashlytics.self, Twitter.self, Digits.self, MoPub.self])
+        // Use Firebase library to configure APIs
+        FirebaseApp.configure()
 
         // Check for an existing Twitter or Digits session before presenting the sign in screen.
         if Twitter.sharedInstance().sessionStore.session() == nil && Digits.sharedInstance().session() == nil {

Step 4. Set up Firebase Crashlytics.

To set up Firebase Crashlytics, follow along in the Firebase Documentation on Getting started with Firebase Crashlytics.

If your Podfile already contains pods for Fabric and Crashlytics, replace them with these version-specific pods:

pod 'Fabric', '~> 1.7.7'
pod 'Crashlytics', '~> 3.10.2'

Once you finish setting up Firebase Crashlytics, you can test your implementation by forcing a test crash in your app.

Step 5: Convert Fabric Answers to Google Analytics for Firebase.

Google Analytics for Firebase (often just called Analytics) provides the same powerful insights as Answers while integrating closely with the rest of the Firebase suite.

Analytics provides many predefined events that we recommend you use. Here’s a table of Answers events and their corresponding Analytics events:

Answers Event Analytics Event (Objective-C) Analytics Event (Swift)
logPurchaseWithPrice kFIREventEcommercePurchase AnalyticsEventEcommercePurchase
logAddToCartWithPrice kFIREventAddToCart AnalyticsEventAddToCart
logStartCheckoutWithPrice kFIREventBeginCheckout AnalyticsEventBeginCheckout
logContentViewWithName kFIREventViewItem AnalyticsEventViewItem
logSearchWithQuery kFIREventSearch AnalyticsEventSearch
logShareWithMethod kFIREventShare AnalyticsEventShare
logRating (No direct corollary) (No direct corollary)
logSignUpWithMethod kFIREventSignUp AnalyticsEventSignUp
logLoginWithMethod kFIREventLogin AnalyticsEventLogin
logInviteWithMethod (No direct corollary) Maybe: kFIREventShare (No direct corollary) Maybe: AnalyticsEventShare
logLevelStart kFIREventLevelStart AnalyticsEventLevelStart
logLevelEnd kFIREventLevelEnd AnalyticsEventLevelEnd

To migrate your Answers code to Analytics, check the getting started guide to make sure you’ve included the necessary dependencies and startup code. If you’ve already initialized Firebase in your app, you can skip ahead to the section titled “Log Events”.

Then, change your Answers logFoo statements (where Foo is an Answers Event in the table above) to Analytics.logEvent using the appropriate event listed in the above table or your own custom event (use your own string instead of one of the constants available in the Firebase library).

The Analytics documentation shows parameters relevant to each predefined event, but you can always add customer parameters too. Instead of using one of the available constants, you can use any string you’d like. Then, register that parameter in the Firebase Console.

If an Analytics event is especially important to your business (such as a user spending money, or completing a critical flow in the app), you can configure it as a conversion.

Read more about how to log events (including how to attach relevant parameters) here.

Contact Support

Feel free to reach out to us if you run into any trouble at: support@fabric.io