Firebase Analytics for NativeScript Mobile App

Hoang Minh Bach
The Startup
Published in
10 min readAug 26, 2020

Collecting and analyzing user behaviour is always a considerable concern of any business because nobody dares to guarantee their mobile application can meet the needs of the end-user.

We need an analysis tool to provide statistics about usage and user engagements with our application which help developers or product managers decide to modify the application when needed. Google provides a solution for this issue called Google Analytics for Firebase.

Google Analytics is a free app measurement solution that provides insight on app usage and user engagement.

Google Analytics for Firebase provides free, unlimited reporting on up to 500 distinct events. The SDK automatically captures certain key events and user properties, and you can define your own custom events to measure the things that uniquely matter to your business.

The Essentials

Initialize NativeScript

In your terminal wherever you want to create this project, do the following:

vue init nativescript-vue/vue-cli-template firebase-analytics

It will ask you some questions (name, description, programming language, vuex, etc.), when answered, the project is created:

cd firebase-analytics
npm install

This step is to navigate to the project folder and install all the dependencies to launch the project.

Now, you are ready to develop a cross-platform mobile app with NativeScript.

Next, you have to install the Firebase plugin:

tns plugin add nativescript-plugin-firebase

This plugin aims to provide a common interface for Firebase instances that can be easily used with NativeScript. While installing these plugins, it will ask some question, some question must be answered Yes (y) which includes:

  • Are you using Android
  • Do you want to enable Firebase Analytics?

Firebase configuration JSON will be generated after install if you choose Yes (y) to answer this question.

Do you want to save the selected configuration. Reinstalling the dependency will reuse the setup from: firebase.nativescript.json. CI will be easier.

Next, you need config multiDexEnable true in App_Resources/app.gradle to avoid this error:

Error: null, Cannot fit requested classes in a single dex file (# methods: 103413 > 65536).

Add Firebase to Android app

Going to “Project settings” to add “Android” app and download “google-services.json”.

Making sure the bundle id or package name is the same as your nativescript.id in package.json and you'll be able to download.

Integrate Firebase plugin to your Android App

Add google-services.json to your NativeScript project at app/App_Resources/Android/google-services.json.

Initialize Firebase app

This step initializes the plugin in our application. The most recommended place to initial is in the main component which is App.vue.

Note: You have to complete this step before following any below step.

When you run an app using tns run android command or tns debug android command to debug app you will see this below massage to inform Firebase is initialized.

Terminal

Page view

Firebase Analytics provides a method called setScreenName to understand the journey of your end-user within your application such as the most favorite screen of the user, first screen user access after sign-in, and so on.

Track event logs

This function will send log Firebase using Firebase plugin which is used when we need to log user event after each activity is executed.

Passing parameters is optional and if you pass parameters, it is always an array includes multi JSON object has 2 properties which are key and value.

User property and user ID

User data can be collected by setUserId and setUserProperty .

Analyze your data

Purpose

The ultimate goal of Firebase Analytics is that you can get detailed information about what your user interaction and engagement of the user with your application base on logging specific events include default events are defined by Firebase and custom events are defined by yourself, screen, property, and so on. Therefore, all of them not only support monitoring activities of your user within the application but also discover who your users are.

Have you ever difficulty tried to answer some questions to analyze user data like the following?

  • Is your app satisfactory enough to keep users engage and introduce your app to the others?
  • How to target audience base on user behavior data?
  • What is the root cause of uninstalling your application?
  • What is the most suitable time to launch new app updates or run marketing campaigns?

In that case, you can separate the type of your user base on behavior information and create a plan to prepare a strategy for your application or your business. Example:

  • Platform: iOS or Android
  • Location: Asia, USA, …
  • Favorite items
  • Most access application screen
  • Gender: Male or Female
  • Age group
Firebase analytics dashboard

Events

Going to “Analytics” -> “Events” on the left side to access event statistics.

Analytics automatically logs some events for the developer; the developer doesn’t need to add any code to receive them. If your application needs to collect additional data, you can create up to 500 different Analytics Event types in your app. There is no limit on the total volume of events your app logs.

Firebase Analytics provides an unlimited number of evens you can log. This means the developer has free-range to log as many events as needed.

If you newly integrate Firebase SDK to your application, event logs will show in statistics within 24 hours.

Events

But you can see your real-time log by clicking the DebugView Report. To enable debug mode in your application execute the below command.

adb shell setprop debug.firebase.analytics.app <your_package_name>
DebugView Report

There are events logs after 24 hours.

Event logs

After the event report appears, to define our custom parameters, we click on a more vertical icon on the left side of each row and choose Edit parameter reporting.

Edit parameter reporting

You should enter the parameter name, choose the type of parameter, and press “Save” to save parameter. The event module will show parameter statistics.

Note: You can define 25 custom parameters per event (Android or iOS). You can also identify up to 50 custom event parameters per project.

Detail of event

I demonstrated selling events for logging data and base on that data, you can know which item is the highest selling or any parameter you defined.

Funnels

Funnel analysis can deliver insight on changes in user actions from logged events. The report expresses the steps which make user drop-off, therefore, it helps you make necessary changes or enhance your user’s experience.

Choose events to your funnel:

Create a funnel

Go inside to your funnel:

Funnel insight
Funnel insight

Take a look at the two above report, you will see the total users at determined steps with a certain sequence.

The second report expresses that all those users opened the application as soon as it was installed. Besides, it exposes whether the user bought items immediately or not after the first view of the application.

One of the most interesting examples is you can build a funnel to get details around a particular collection of events that able to lead to uninstall your application. To do that you should create a funnel include app_remove event and get inside collected data reports such as location, gender, age, and so on to figure out who and when to tend to uninstall your application.

Ultimately, the most important thing you should know is that you are obligated to understand the behavior of a user, from that you can know what user needs, what brings high-value benefits and what is unnecessary to minimize or eliminate them using Kano analysis.

User property

The other important thing about analytics is that many reports and graphs you need in the Firebase console are user properties. You can get specific data by filtering user property via multiple conditions. Also, user properties in your reports are broken by each value.

Note: You can set up to 25 different Analytics User Properties per project and should save meaningful data together about the group such as favorite, type, range, and so on because the information we will get is filtered a data based on your conditions.

Log event and set user property in Debug Mode

To create a user parameter for filtering, you click “User property” on the left side and click “New user property” to create a new property.

Create new user property

Now you will see the filter condition in the Events Dashboard.

Filter events by a user property

You click “Apply” to look at the event graph base on your filtering. In this example, you will see events only related to users who have a “football” favorite and you will know which population actually prefers. Besides that, you can filter default parameters that are defined by Firebase such as gender, OS, and so on.

Filter events by favorite=football

All of this help you determine important factors, prioritize your product backlog, target the right audiences for campaigns, or where you want to spend your marketing money.

BigQuery

The logging event method saves all of the user logs which is defined by Firebase or yourself, all of this data can be used to train a model for machine learning or transformed to information and visualize by BigQuery.

The suggestion at the events module of Firebase

BigQuery is a fully-managed, serverless data warehouse that enables scalable analysis over petabytes of data. It is a serverless Software as a Service that supports querying using ANSI SQL. It also has built-in machine learning capabilities.

  • Analyze petabytes of data using ANSI SQL at blazing-fast speeds, with zero operational overhead
  • Run analytics at scale with 26%–34% lower three-year TCO than cloud data warehouse alternatives
  • Democratize insights with a trusted, and more secure platform that scales with your needs
  • Gain insights from data across clouds with a flexible, multi-cloud analytics solution

BigQuery is out of the article’s scope so that I just mention here and don’t go to deep in detail.

Gender

Getting gender information in your own ways is impossible and unnecessary because Google Firebase get that information via Google account downloaded your application.

Percentage of events triggered by each age group and gender.

Location

Location information is automatically collected by Firebase when the user setup or use your app.

Percentage of events triggered by each of your top countries.

Platform

This information is collected by Firebase when users use the application.

Platform

User retention

This report helps you know a higher retention rate as compared to the other and the amount of retention decrease by week.

Base on this information, you are able to make a decision about modification of your application or create some strategic plan to retain user and increase the number of users depend on your business or market and when is the most appropriate to implement your plan.

How to retain users?

Example: Using this report, you can determine when users tend to leave your application so that before it, you should use notification to give them some promotion or incentive and so on to keep them engage in your app.

Crash Application

This data provides the percentage of unexpected crash application logs which is used to check stable of application and fix a bug as soon as possible. Crashing application is one of the most serious cause that business loses user.

The percentage of unexpected crash application

Active users and daily user engagement

You can check the number of active users and daily user engagement which is the average of time spent using your software.

The number of active users
Daily user engagement

StreamView

Steamview provides some statistics such as trending, timeline, top event, top location, map, and location maker, and so on in realtime, so that, you can view the number of events and user and know what your user interact which your app at present.

Streamview

Conclusion

Firebase Analytics which track user data and events very efficiently, can be integrated easily, provides enough function to collect and particular metrics to analyze data but with advanced analysis, we need another framework to work with Google Firebase such as BigQuery. This article just provides basic information to the reader for understanding the way Firebase Analytics work. Maybe, this article still has some shortcomings so that I always welcome feedback from all of you. Thanks for reading.

--

--