Firebase Analytics: Getting Started

Learn how Firebase Analytics can help you track iOS app usage. By Danijela Vrzan.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 3 of 4 of this article. Click here to view the first page.

Viewing Events in DebugView

Open the Firebase Console and, under Analytics in the left pane, click DebugView.

Build and run. Order some cookies. When you tap Confirm Order, an event in the timeline will appear.

It might take a while for the events to show, but after a few seconds you’ll see them on the screen:

Firebase Console screen showing DebugView tab and a timeline view of all logged events

On the right side, you’ll see a list of events logged in the last 30 minutes. Click an event name to see all of it’s properties:

Windows with detailed information about a specific event that was selected in the timeline of DebugView

Exit the view by clicking x.

Viewing Events in the Firebase Console

While debug mode is useful when you’re developing, you’re more likely to view a collection of data under Events in the left pane of the Firebase Console:

Firebase Console showing Events screen with a list of all logged events in the past 30 days

Note that it can take up to 24 hours for the events to show.

This report shows the analytics data from all your apps, both iOS and Android.

Big companies often have dedicated teams to track and analyze analytics. There could be hundreds of events tracked in one app, depending on the end goal.

When you have that much data and you’re doing a serious in-depth analysis, you can export your data into BigQuery, which is a Google data warehouse service. This tutorial doesn’t cover BigQuery, but if your app is tracking a lot, it’s worthing looking further into the service.

User Properties and Audiences

While seeing a data collection is nice, sometimes you want to break it into more specific user segments.

It’s great to see people are visiting your in-app store but, who are these people?

Are they new users? Dog owners? Canadians?

Knowing who your users are can make it easier for you to analyze data in greater detail.

Filtering With User Properties

By default, Firebase Analytics provides some segments for you. You can filter any particular event by device type, gender, country and more.

Open the Firebase Console and create a new filter. Click Add Filter in the top left of the Dashboard. Select a user property you want to filter by, like all your iPhone users:

Firebase Console showing Dashboard screen with filter option turned on to filter users that have used the app on iPhone

Often you might need more specific data. For that purpose, you can create custom user properties.

You add custom user properties by defining a key-value pair.

After you assign a user property to a user, all events from that point on have that user property associated with them.

You can define more than one user property, but keep them to a small number of discrete values if you want to make your life easier. Having too many events and user properties will only make it harder for you to track who did what and who is who.

Your marketing team has a theory that cat people are more likely to make in-app purchases than dog people. They want to back up that claim with data. This sounds like a job for custom user properties.

Adding Custom User Properties

It’s time to add some functionality to the left questionnaire button on the main screen.

Build and run. When you tap the nose button in the upper left corner, an alert will pop up and ask you whether you’re a cat or a dog person:

iPhone simulator showing running Cocoabucks app and a questionnaire alert screen asking if you're a dog or a cat person

Once a user answers the questionnaire, they’ll have a custom user property assigned to them. Because you have a tight deadline, you’ve made sure there’s no exit button on the modal window.

Open ProductListView.swift and add the following to the top of the file:

import Firebase

Adding a user property is straight forward.

You already have the alert view set up, so all you have to do is add a user property to each selection button.

At the bottom of the view’s body, find the alert modifier.

You’ll see an empty action for both the dog and cat buttons.

Inside an action of a primary, or cat, button, replace // TODO 3 with:

FirebaseAnalytics.Analytics.setUserProperty(
  "cat_person",
  forName: "dog_or_cat_person")

Do the same for the secondary, or dog, button. Replace // TODO 4 with:

FirebaseAnalytics.Analytics.setUserProperty(
  "dog_person",
  forName: "dog_or_cat_person")

You set a user property with setUserProperty(_:forName:). Give it the custom name dog_or_cat_person and two values: dog_person and cat_person.

Build and run. Open the questionnaire and select an answer.

Somewhere in your Xcode console, with the debug view turned on, a new line will appear:

Custom analytics event log in Cocoabucks console

It doesn’t tell you much, only that a user property has been set. Play with the app and trigger different events.

Viewing User Properties in DebugView

Open the Firebase Console and click DebugView. You’ll see a new user property recorded in the orange text:

Firebase Console screen showing timeline in the DebugView and a user property being set in orange text

If other events were logged after the user property was set, they’ll each have an assigned user property.

Before you can filter out these events based on a user property’s value, you have to create one in the Firebase Console.

Adding User Properties in the Firebase Console

Still in the Firebase Console, click Custom Definitions in the left pane.

Firebase Console showing Custom Definitions window

Click Create custom dimensions and a New custom dimension window will appear.

Firebase Console showing Custom Definitions panel and a new window where you type the information to add a new custom dimension and in this case set a new user property for the events

Give your dimension a descriptive name as it’ll appear in all your reports. You can use the same name as the name of your user property.

Under Scope drop-down, choose User. Give it a description.

Note: When you set user-scoped custom dimensions, never include personally identifiable information such as names, social security numbers, or even email addresses.

Copy and paste dog_or_cat_person from Xcode to User property. It’s best to copy and paste it because you can’t rename it once you add the user property. Also, there’s a limit of 25 custom user properties.

Click Save.

From this point on, when the Firebase Console logs new events, you’ll be able to filter them by the value of your custom-defined user property.

So who wins? Do cat people buy more cookies?

Creature monster eating a bunch of cookies

Tailoring User Experiences with Audiences

Firebase Analytics is even more powerful with Audiences.

They give you the ability to create groups of users who meet certain criteria. You can think of them as advanced filtering options. They can be broad or narrow and help you deliver personalized user experiences.

Open Audiences in the Firebase Console to see some already added there:

Firebase Console showing Audiences screen and how it looks like when there are audiences set up

Because you added predefined purchase events, Firebase added Purchasers for you. That’s the beauty of using predefined events.

Consider the next use case.

A user views one or more products in your app, goes to the checkout screen but doesn’t complete the order.

These actions only tells you that the user opened the app, wanted to make an order but dropped it before completing it. That could mean there’s something wrong with the checkout process, the order failed or the user closed the app.

You can’t know for sure.

Funny custom image showing how to distinct certain users and add them to custom audiences

You can create an audience of these users. Give it a name and define a list of events to log. Think of it as a to-do list where you need to complete all items in the list before you mark the list as finished.

When Firebase detects such events, it puts that user in the specified audience. You can personalize the app only for those specific users by having an audience.

Finally, you can ask those users why they haven’t completed an order with an in-app pop-up screen. You can get concrete feedback from users who are part of that audience without bugging the rest of them.

Where do you think Google gets those personalized ads from? Your friend sends you a message about his trip to the Bahamas, and now, for the rest of your life, you’ll see the Bahamas everywhere.