Getting Started with Firebase Analytics for Apps

/

Getting Started With Firebase Analytics for Mobile Apps

Firebase Analytics is an analytics tool specifically designed for apps. It is part of the larger Firebase SDK, a mobile development platform that helps you use Google services when building iOS and Android apps. There are a variety of other tools built into the Firebase SDK, but for our purposes we are only focused on utilizing Firebase Analytics.

This post aims to provide the stepping stones for getting up and running with Firebase Analytics for your mobile app, as well as sending the information to your Google Analytics mobile app property.

Background

Firebase Analytics

What does it cost to use Firebase? According to the documentation, there is no charge for using Firebase to collect events about user activity on your apps. There are no limits or tiers for the amount of data collected – there is only a limit to the number of types of events you collect (the names given to the events you are tracking). You can have up to 500 different event types or names, which should be plenty in most cases.

Note: Firebase data is oriented around events instead of screenviews – you will essentially be logging events into Firebase with optional parameters containing additional information about the action that occurred. This is different than the traditional form of app tracking with Google Analytics where data is screenview-oriented and your reports look very similar to a standard web Google Analytics property (which is pageview-oriented). However, you can use Firebase and GTM in tandem to get both – we’ll walk through how to do that in this post as well.

Google Tag Manager

Firebase hooks into the Google Tag Manager (GTM) dataLayer, making integration with Google Analytics very straightforward. When events are logged to Firebase (as instructed later in this post), GTM can be used to collect and send that data to Google Analytics as well, which will make it possible to provide roll-up reporting with website data for a bigger picture of how users are engaging with all of your digital properties.

Note – These instructions are geared towards fully native apps. If your app is a hybrid app (such as a PhoneGap app), you may need to customize your implementation.

Summary of Steps

Here we’ll focus on the basic steps to getting set up and logging Firebase events, as well as tracking those same events with Google Analytics screenview and event tracking. Firebase offers a variety of additional features and functionality that could not be fit into this one blog post, but there are many links to Google’s documentation throughout if you want to learn more as well.

The general steps we will walk through include:

  1. Set up Firebase Account
  2. Install Firebase SDK
  3. Install GTM SDK
  4. Log Firebase Events
  5. Bonus: Send Screenviews and Events to Google Analytics

Firebase Account Setup

Follow the steps below to set up a new Firebase account for your Android and/or iOS app.

If you have both an Android and an iOS version of your app, you can either set them up with separate Firebase accounts or set them up within the same Firebase account. If you want to set them up within the same Firebase account, you’ll need to set up one first and then add the second within the Project Settings. This will allow you to toggle back and forth between data for the Android and iOS apps, for example (the data will not be combined).

04-add-app

Getting Started

Have your package name ready for your Android app and/or your Bundle ID ready for your iOS app (ask your developers for this).

Go to console.Firebase.com and create a new project.

01-create-firebase-project

Once you’ve created a new project, you’ll see the overview screen. Down the left-hand side you will see many of the Firebase features, such as Crash Reporting and Analytics. We’re going to be working with Firebase Analytics.

02-firebase-account-overview

In the center of the screen you’ll see options to Add Firebase to your iOS app, Add Firebase to your Android app and Add Firebase to your web app. Click on the appropriate option for your app (disregard the web app option for now), you will be prompted to enter your app’s package name (Android) or Bundle ID (iOS).

03-enter-bundle-id-for-ios

Get the Config File(s)

Once you have provided your Bundle ID or Package Name you will be given a config file along with instructions on where to place it in your app. You will also be provided with steps to installing the config file and installing dependencies for your Android or iOS app. Follow each of the steps as instructed.

Examples for both Objective-C and Swift are provided for iOS.

Go to Analytics from the left-hand navigation and you will see a variety of reports are available, including a Dashboard, Events, Audiences, and more:

05-analytics-overview

There are other data points that Firebase can collect (such as user properties), but we’ll save those for a later post. Today we’re only concerned with logging Firebase events and setting up basic screenview and event tracking for Google Analytics. Check out this handy resource to learn more about the Firebase Analytics reporting interface.

While You’re At It – Take It A Step Further

While we’re setting up Firebase, there are a few other tools that we can use in tandem. Consider the differences between the tools and how much effort is required to track into multiple tools. In our case, it’s not much effort at all!

Google Analytics

This one we’ll cover in this post – set up a Mobile Google Analytics property and use GTM to piggyback off the Firebase events in order to send screenviews and events to Google Analytics as you would with analytics tracking on a website using GTM. Make sure you select the Google Analytics Services SDK option, not the Firebase option (more on the Firebase option at the very end of this post):

06a-new-ga-property

We generally recommend doing this in addition to using Firebase Analytics because you reap the benefits of both sets of reports. Google’s documentation actually lays out a few good points you can use to decide whether you want to use Firebase Analytics, Google Analytics or both. Some best practices are also provided for deciding how to segment the data into different properties in Google Analytics as well.

For the purposes of this post, we’re going to assume you are interested in configuring both Firebase Analytics and tracking screenviews and events in Google Analytics and that you have a mobile Google Analytics property ready.

BigQuery

For another day – BigQuery Integration! Enough said, right? Well, except a quick note on billing: you will have to enable a billing account for Firebase (since BQ is a paid tool) and choose the “Blaze” (pay-as-you-go) plan. If you’re not using the Firebase features other than Analytics (other features like Realtime Database, File Storage, etc.) you shouldn’t have any charges aside from BigQuery storage and query processing. In the Firebase project, select the gear icon in the left nav, Project Settings. Then go to the Account Linking tab and choose BigQuery.

Install Firebase SDK

You will need to refer to the documentation for installing the Firebase SDK on your app:

Note that at the bottom of both sets of instructions there are additional services you can enable, such as crash reporting. Enable that and any other service relevant to your app.

Install GTM SDK

As I mentioned earlier, we’re going to use GTM for collecting Firebase events and sending them to our mobile Google Analytics property in order to enable a new suite of reports that we otherwise would not get with Firebase alone.

First we need to make sure we have a GTM container to add to our app. Go to http://tagmanager.google.com and create a new container for your app(s). Select the appropriate operating system and choose a Firebase container:

07-create-gtm-container

Once you do this, you will immediately be provided with a link to instructions on installing the GTM SDK for your app:

If you peek ahead in those instructions, you’ll see some examples for logging events. You’ll also see this important note:

Google Tag Manager uses Firebase Analytics’ events, parameters, and user properties to trigger and build tags you’ve configured in the Google Tag Manager web interface. In this sense, your Firebase Analytics implementation acts as your data layer.

This is a key point referring to how GTM and Firebase work together. In fact, you could completely ignore the Firebase Analytics reports altogether and simply use the platform to log events to the “data layer” for GTM, ultimately using GTM to send data to Google Analytics if you prefer the screenview-oriented reports.

Log Firebase Events

You should have a strategy in place for how the data is going to look before you request it from your developers. If you want to capture screenviews, you’re likely going to want to see the screen name of the screen that was viewed, for example. It may be helpful to create a spreadsheet to organize all of the actions you want to track and the details you want to collect about those actions.

The two documents I linked to last show some examples of how you would log events. For example, the Android documentation shows example code that looks like this:

In this example, share_image is the name of the custom event, and the image_name and full_text are additional pieces of information that are provided as parameters.

If you’re not sure how to label your events, check out Google’s list of suggested events.

Better yet, there are certain events that are automatically logged to Firebase for you (but not to Google Analytics), such as first_open. We won’t go into detail on those, but if you’re interested you can check out the documentation for those.

For additional information on logging events, there is more thorough documentation for that:

Ok, so once those new custom events are logged to Firebase from within your app, you will begin to see them in your Firebase Analytics account (typically within a few hours, but it can take longer). They will appear in the Events tab along with the events that are automatically logged for you:

14-firebase-event-list

You will not need to configure tags in GTM in order to see the Firebase events that you are logging.

You will need to set up tags in GTM to pass this data along to Google Analytics as traditional screenview and event tracking, however.

Send Screenviews and Events to Google Analytics

As I said, events that are logged to Firebase will appear in Firebase Analytics reports – you will not need to configure tags in GTM to see them there. However, if you want to also send that data to Google Analytics, you will need to capture it with variables and set up Google Analytics tags.

Google Analytics Screenview Tracking

Here’s an example of how an event might be logged in an Android app for a screenview:

In GTM – we can take this information, break it apart into pieces, and then use that to send information to Google Analytics. Let’s start from the bottom up – Variable, Trigger, then Tag.

Use an event parameter variable to pull in the screen name from the Firebase event being logged from your app:

12-event-param-screen-name

Then create a trigger that listens for Firebase events called “screenview:”

09-screenview-trigger

Lastly, you’ll need to create a Google Analytics tag for your screenview. We can set the tracking ID to your new Google Analytics mobile app property.

08-screenview-tag

You’ve just created your first screenview tag using Firebase and GTM! Once the GTM container is published, screenview hits will be collected in the mobile app Google Analytics property:

16-screenview-in-ga

Google Analytics Event Tracking

So now that we have our screenviews tracked, let’s set up some event tracking. Let’s use an iOS example this time, written in Swift, of an event that might be logged when a user performs a search on the app:

This example comes from Google’s list of suggested events mentioned earlier.

To capture this with Google Analytics event tracking, we’ll again start from the bottom and work our way to a Tag.

We can reuse that same event parameter variable created earlier to pull in the screen name from the Firebase event being logged from within the app:

12-event-param-screen-name

Create another event parameter variable to pull in the search term for the event action:

13-event-param-search-term

Then create a trigger that listens for Firebase events called “search:”

11-event-trigger

Finally, set up a new Google Analytics tag:

10-event-tag

Again, set the tracking id to the Google Analytics mobile app property.

Once you publish GTM with these updates, event tracking data will appear in the mobile app Google Analytics Event reports:

17-events-in-ga

Troubleshooting

Now that you’ve set up these tags, you’re probably wondering how to test them. Testing Firebase and Google Analytics on a mobile app can be especially challenging, and is certainly worthy of its own blog post. Some of the most common tools for debugging include:

  • Charles Proxy, Fiddler, WireShark or similar network request sniffing tool – You can configure these to listen to the network requests sent out from your app, check the parameters that are provided for accuracy, etc.
  • Android Studio console – Log console events in Android Studio while testing configurations with an Android emulator.
  • Xcode debug console – Same idea as the Android Studio console, but for iOS.
  • Google Analytics Real Time Reports – While app hits can take a few minutes little longer to appear in Real Time reports, they should appear there while you’re testing. This can be extremely helpful, especially considering the fact that Firebase does not offer Real Time reporting.

Summary

I hope this is a clear yet useful guide to getting up and running with Firebase Analytics. There are plenty of other Firebase features we could talk about in future posts. If you’re curious, check out Jimmy’s review of Noteworthy Features of Firebase Analytics.

Keep in mind that if you have a hybrid app (using web components and native components), you may need a MUCH more complex solution. If you’re not sure whether your app is fully native or a hybrid, talk with your developers before getting started with setting up Firebase.

Note that you can also set up a new Firebase Google Analytics property and link it to your new Firebase account in order to bring those same Firebase reports into Google Analytics:

06b-new-ga-property-firebase

This means you can see your Firebase reports in the Google Analytics interface rather than having to switch to Firebase to see your app data. I kept this piece of information out of the original list of Additional Opportunities in order to prevent confusion throughout the setup instructions – this is not as useful as setting up a mobile app Google Analytics property, in my opinion.

Amanda Schroeder is an Analytics Engineer and comes from the marketing industry where she found a need for accurate, insightful data that could aid in making results-driven decisions. Amanda’s passion for building solid measurement strategies and connecting all the pieces of integrated digital and traditional marketing campaigns has led her to her current role at LunaMetrics.

  • Steve Guberman

    GREAT POST!!! Thanks for sharing all this amazing information.

    • Amanda

      Thanks Steve, glad you found it useful!

  • spiros skaliotis

    How i can use firebase to make my application better?

  • Patricia

    Thanks for the great post! Very helpful!
    If I understood correctly, this means that you need to make one GTM tag per event tracked in Firebase?

    • Patricia

      What about the events tracked automatically by Firebase? Do we also need to make individual GTM tags for each of those, so that we can see them in GA?

      And the automatic user properties? (https://support.google.com/firebase/answer/6317486?hl=en&ref_topic=6317484) Do they also need to be GTM variables?

      • Amanda

        Hi Patricia,

        Yes, you need to set up Universal Analytics tags if you want to see the data in Google Analytics.

        The events that are tracked automatically for Firebase are not tracked automatically in Google Analytics – you will need to set up Universal Analytics tags in GTM for those as well.

        The user properties will need to be added as variables in GTM if you want to attach them to Universal Analytics tags to get that data into Google Analytics.

        Best,
        Amanda

        • Patricia

          Thanks Amanda! 🙂

          • Amanda

            Sure thing!

  • Guio

    Hi!
    That’s a great step-by-step post, thanks a lot Amanda!
    I’m working in a project that are developing a hybrid mobile app, where can we find more information about how customize firebase implementation?
    I love the idea of firebase work as a datalayer for GTM; so, an hybrid app won’t make any difference in setting up GTM and tags, right?
    Thanks

    • Amanda

      Hi Guio,

      Unfortunately, I have not found any resources or documentation on customizing Firebase for hybrid apps. I think we should write a blog post about that topic because it is fairly complex and there are a few different ways to handle it, but until then here are a few things to consider:

      Will the hits / tracking be handled entirely on the native app side? For instance, sometimes hybrid apps are configured in a way where activity in the web-driven parts of the app is actually passed to the native side, where Firebase is then used to track it.

      However, if there are various parts of the app that are web-driven that will be tracked within webviews, for example, that will likely need to be tracked separately because Firebase cannot be used there. If you are dealing with this scenario, you will likely need a standard web GTM container on the web-driven parts of the app. This means you will end up with two GTM containers – one Firebase GTM container for the native app side of things and one standard web GTM container for the web driven side of the app.

      Talk with your developers and see which path they are considering. As I said, this topic really deserves its own blog post…. Perhaps that will be my follow-up topic 🙂 I hope this gives you an idea of the complexity here.

      Best,
      Amanda

Contact Us.

LunaMetrics

24 S. 18th Street, Suite 100,
Pittsburgh, PA 15203

Follow Us

1.877.220.LUNA

1.412.381.5500

getinfo@lunametrics.com

Questions?
We'll get back to you
in ONE business day.