/firebase-tutorials

How to track custom events in Firebase analytics?

Learn how to integrate Firebase Analytics into your Android/iOS app, log custom events, debug them, and review insights in the Firebase Console with our step-by-step guide.

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 track custom events in Firebase analytics?

 

Step 1: Set Up Firebase in Your Project

 

Before you can track custom events in Firebase Analytics, you need to set up Firebase in your app. Follow these steps:

  • Go to the Firebase Console.
  • Click on "Add project" and follow the on-screen instructions to create a new Firebase project.
  • After the project is created, click on "Add app" to add your mobile app to the project. Choose the appropriate platform (iOS or Android) and follow the setup instructions.
  • Download the google-services.json file for Android or GoogleService-Info.plist file for iOS from the Firebase Console and integrate it into your project.

 

Step 2: Add Firebase SDK to Your App

 

You need to add the Firebase SDK to your app to enable analytics. The following snippets show how you can do this for both Android and iOS:

For Android:


// Open your app's build.gradle file and add the following dependencies:
dependencies {
    // Add the dependencies for the Firebase SDKs you want to use.
    // For example, to use Firebase Analytics, add:
    implementation 'com.google.firebase:firebase-analytics:21.0.0'
}

For iOS:


// Open your Podfile and add the FirebaseAnalytics pod dependency:
pod 'Firebase/Analytics'
  • Run pod install in your terminal for iOS or sync your Gradle files for Android.

 

Step 3: Initialize Firebase in Your Project

 

Make sure Firebase is initialized once your app starts. Here's how you can do this:

For Android:


@Override
public void onCreate() {
    super.onCreate();
    // Initialize Firebase
    FirebaseApp.initializeApp(this);
}

For iOS:


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(\_ application: UIApplication, 
             didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Initialize Firebase
        FirebaseApp.configure()
        return true
    }
}

 

Step 4: Log Custom Events in Firebase

 

Now that Firebase is set up, you can log custom events to track specific user interactions. Use the following method to log custom events:

For Android:


// Obtain the FirebaseAnalytics instance.
FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

// Log a custom event.
Bundle params = new Bundle();
params.putString("image_name", "example_name");
params.putString("full\_text", "Example full text");
mFirebaseAnalytics.logEvent("share\_image", params);

For iOS:


import Firebase

// Log a custom event.
Analytics.logEvent("share\_image", parameters: [
    "image_name": "example_name",
    "full\_text": "Example full text"
])

 

Step 5: Debug and Verify Custom Events

 

To ensure your custom events are logged correctly, you can use the built-in debugging utilities from Firebase:

For Android:

  • Use Android Logcat. You can filter logs using the tag FA to view Firebase Analytics logs.
  • Run your app and perform the events you logged, then check Logcat for confirmation.

For iOS:

  • Use the Xcode Debug Console. Launch your app with Xcode, perform your custom events, and view the console for analytics messages.

 

Step 6: View Events in Firebase Console

 

Once events are set up and verified in your app, you can view them on the Firebase Console under the Analytics dashboard:

  • Go to the Firebase Console.
  • Select your project.
  • Navigate to the "Analytics" section and look for "Events" to review your custom events.

By following these steps, you can successfully track custom events in Firebase Analytics to gain insights into user behavior in your app.

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