/firebase-tutorials

How to use Firebase analytics in web app?

Learn to integrate Firebase Analytics in your web app by setting up a project, adding the SDK, enabling Analytics, and tracking user events for insights.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to use Firebase analytics in web app?

 

Step 1: Set Up a Firebase Project

 

To use Firebase Analytics, you need to set up a Firebase project.

  1. Go to the Firebase Console.
  2. Click on Add Project.
  3. Enter a name for your project.
  4. Follow the prompts to complete the project setup.
  5. Once your project is created, you’ll be redirected to the Firebase project overview page.

 

Step 2: Add Firebase to Your Web App

 

  1. In the Firebase Console, select the web app icon (</>) to add Firebase to your web app.
  2. Enter a nickname for your app (optional), and click Register App.
  3. Firebase will present a code snippet.

Include the Firebase SDK in your project by adding the following <script> tags to your HTML file:

<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/10.3.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.3.1/firebase-analytics.js"></script>

<!-- TODO: Add SDKs for Firebase products that you want to use -->

Initialize Firebase in your app by adding the following JavaScript code to your project:

// Your web app's Firebase configuration
const firebaseConfig = {
  apiKey: "YOUR_API_KEY",
  authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
  projectId: "YOUR_PROJECT_ID",
  storageBucket: "YOUR_PROJECT_ID.appspot.com",
  messagingSenderId: "YOUR_SENDER_ID",
  appId: "YOUR_APP_ID",
  measurementId: "YOUR_MEASUREMENT_ID"
};

// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();

Replace "YOUR_API_KEY", "YOUR_PROJECT_ID", etc. with the specific details for your project.

 

Step 3: Enable Google Analytics for Your Firebase Project

 

  1. In the Firebase Console, navigate to the Project Settings.
  2. Under the Integrations section, find Google Analytics and click Enable.
  3. Follow the prompts to complete the integration setup.

 

Step 4: Use Firebase Analytics in Your Web App

 

Now that Firebase Analytics is set up in your app, you can start logging events.

To log a specific event, such as a user clicking a button, you can use the following code:

document.getElementById('yourButtonId').addEventListener('click', () => {
  firebase.analytics().logEvent('button_click', {
    button_name: 'yourButtonName'
  });
});

Replace 'yourButtonId' and 'yourButtonName' with the specific details of your application.

 

Step 5: Verify Events in the Firebase Console

 

  1. Return to the Firebase Console.
  2. Navigate to the Analytics section.
  3. You should see the events logged from your web app under Events.
  4. Use these insights to understand user interactions within your app.

 

Conclusion

 

With Firebase Analytics integrated into your web app, you can now track user behavior, understand engagement, and make data-driven decisions to enhance your product. Be sure to explore other Firebase services to fully utilize the potential of Firebase for your web applications.

 

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022