Analytics is one of the important tools that developers should definitely used while building their applications. It is very helpful to target your apps for various audience ranges and to track on which screen the users are spending a long time. So it is one of the important features which one should not miss adding while building any Android Application. Firebase is one of the famous online platforms which is a product of Google which offers analytics services for free. This analytics can be integrated inside our app along with Firebase and you can get to see the events of your application and track your audiences very easily. In this article, we will be integrating Google Analytics inside our Android application.
What are the benefits of using Firebase Analytics?
- Google Analytics provides unlimited reporting with up to 500 different events.
- With the help of Google analytics, you can define custom audiences on the basis of device data, and custom properties.
Step by Step Implementation
Step 1: Create a new Android Studio Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.
Step 2: Connect your app to Firebase
After creating a new project in Android Studio connect your app to Firebase. For connecting your app to firebase. Navigate to Tools on the top bar. After that click on Firebase. A new window will open on the right side. Inside that window click on the Analytics tab and then click on Log an Analytics event.
After clicking on Log an Analytics event you will get to see the below screen. Inside this screen click on the first option connect to firebase and after that click on the second option to add Analytics to your app.
After clicking on both the options you will get to see the below screen.
Step 3: Verify that the dependency of the analytics has been added to your dependencies section
Navigate to the app > Gradle Scripts > and click on build.gradle file and verify that the below dependency has been added or not.
After adding this dependency you have now added Firebase Analytics inside your app. Now your app has been connected to Firebase and analytics has been added to your app. We don’t have to add any code in XML and Java files. Now run your app and you can get to see analytics that has been added to your app. Now we have to enable Analytics in Firebase Console.
Step 4: Open Firebase Console and click on the Analytics section on it
Browse Firebase in your Browser and click on Go to Console option in the top right corner.
After clicking on this screen you will get to see the below screen with your all project inside that select your project.
After clicking on your app, click on the Analytics tab in the left window you will get to see the below screen.
After opening this screen click on the Enable Google Analytics section.
Click on the Enable Google Analytics section and you will get to see the below screen to select your Analytics account.
After clicking on the Enable Google Analytics option you can go to Step 2 and then click on the Finish option to enable Google Analytics for your app.
After enabling your Firebase Analytics you will get to see the below screen.
Now run your app. Firebase Analytics has been enabled in your App and you will get to see events being tracked in the blue section of the Firebase Analytics console. You will not get to see any output on your mobile app. You can see the events in your Firebase Console.