Simple Firebase Analytics Setup for a React Native Android Project

I tried setting up Firebase Analytics in my React Native app recently and found a lack of clear, simple, and straightforward resources on the internet. However, I was able to successfully set it up and would like to share the steps I followed for others who may be struggling with this.

Step 1:

Create an account and property in Google Analytics:

While creating the property, you will see the below step. Choosing "Android app" here will show steps to create a new Firebase project for your app.

In the next step, you should provide your app's package name. It is specified in - app/build.gradle - just search for applicationId within the file. It should look something like this: "com.example"

Register the app and make sure to follow the remaining setup instructions mentioned there i.e. Steps 2 to 5 in the above screenshot.

Step 2:

In the terminal, run the below command at the root of your react-native project. It will install the packages necessary for Firebase analytics.

yarn add @react-native-firebase/app @react-native-firebase/analytics

Step 3:

Now you can start implementing the code.

import analytics from '@react-native-firebase/analytics';

const onButtonPress = () => {
  analytics().logEvent('button_press'); // Use any event name of your choice

Step 4:

Now, rebuild the app and perform the button press action. If everything is set up correctly, within 15 minutes, the users count will change to 1 on your Google Analytics Dashboard. The actual analytics will start showing up 24 hours later.

That's it! Read the documentation for more details on the code implementation:

If you found this article useful, please leave a clap. Thanks for reading!

- Teja Karlapudi