Loading...

Integrating Google Firebase Analytics to your Android Project

Firebase is a cloud service provider and backend as a server for mobile and web app. Firebase was founded in 2011 and launched with a real time cloud database in April 2012. Firebase has many features; most of them are free while some are paid. Firebase include mobile app analytics (Android, iOS, etc), cloud messaging, firebase auth, storage, hosting, remote config, test lab for android, crash reporting, send notification to the users, app indexing, dynamic links and send personalized email and SMS invitation, measuring the impact of invitation.

In this tutorial, you will learn to integrate or add Google firebase analytics to your android project. Firebase analytics collects usage and behavior data for your application or game. If you already integrate any of the firebase services in your android app or game then adding firebase analytic is very easy. If not, don’t worry. In this tutorial, I will show you step-by-step guide to integrate Google firebase and firebase analytic in your android application with simple example and you can download this sample project source code from GitHub at last.

Related:
Android Push Notification Tutorial Using Firebase
How to Integrate Google AdMob in Android
Google Maps Android API Getting Started Tutorial : Part 1

Integrating Google Firebase Analytics to your Android Project: Get Started with Firebase Analytics for Android


Before starting to add google firebase analytic to your android project, make sure your device is running Android 2.3 (Gingerbread) or newer, and Google Play services 9.2.1 or newer and Android Studio 1.5 or higher.

Integrating Google Firebase Analytics to your Android Project: Get Started with Firebase Analytics for Android

1. Create a new Android Project using Android Studio


Create a new android project with the package name: Add Firebase Analytics to Android Project and select minimum SDK: API 9 Android 2.3 (Gingerbread) or higher.

2. Install the Firebase ADK to your Android Project


To integrate the firebase libraries into your own android project, you need to perform certain tasks.

2.1. Open your project level (top level) build.gradle file and add classpath 'com.google.gms:google-services:3.0.0' as a dependencies. Your project level build.gradle file will look like below.

Project level build.gradle file

2.2. Now open your app level build.gradle file and add compile 'com.google.firebase:firebase-core:9.2.1' as app dependencies and apply plugin: 'com.google.gms.google-services' at the bottom. Your app level build.gradle file will look like below.

App level build.gradle file

3. Adding Internet Permission in your Application AndroidManifest.xml File


In your app’s AndroidManifest.xml file you need to add internet user permission. Open AndroidManifest.xml file and add android.permission.INTERNET which is look like below.

AndroidManifest.xml

4. Add Your App to Your Firebase Project in the Firebase Console


4.1. Go to Google Firebase Developer Console

Add Your App to Your Firebase Project in the Firebase Console

4.2. Create new project.
4.3. A dialog box will appear, add project name: Google Firebase Analytics and choose your country and click Create Project button.
4.4. After creating new project in Google firebase developer console, new screen will appear like below.

Add Your App to Your Firebase Project in the Firebase Console

4.5. Click add firebase to your android app. Here you need to provide your app package name.
4.6. Add project package name in the box and click Add App button. A file google-services.json is downloaded. Click Continue and Finish button.

5. Adding google-services.json File to Your Project


5.1. Go to android studio. Switch to the project view in Android Studio.
5.2. Add google-services.json file that you just downloaded to your android app directory like the screenshot below.

Adding google-services.json File to Your Project

6. Adding Firebase Analytics for Android to Your Android App


In android studio, again open app level build.gradle file and add compile 'com.google.android.gms:play-services-analytics:9.2.1' as app dependencies. Following is the final content of app level build.gradle file.

App level build.gradle file

7. Check Your App Report in Google Firebase Analytics


7.1. Go to Firebase Developers Console.
7.2. Choose your app
7.3. Click Analytics from left menu. For the first time, it will look like below.

Check Your App Report in Google Firebase Analytics

After some hours or day you can see your app’s complete reports like below.

Check Your App Report in Google Firebase Analytics

That’s all. You have done all things. Now you can see your application’s complete report in Google firebase analytic. It’s very easy and simple to integrate.


8. Java Activity File and XML Layout File


Following is the content of XML layout file.

res/activity_main.xml

Following is the complete content of java activity file.

src/MainActivity.java

Download Complete Project Source Code

You can download complete example project source code from GitHub.
Tutorial 1744506523356431809
Home item