Skip to main content
RapidDev - Software Development Agency
firebase-tutorial

How to Track Custom Events in Firebase Analytics

To track custom events in Firebase Analytics, call logEvent() from the Firebase modular SDK with an event name and optional parameters object. Custom events let you measure actions specific to your app beyond the automatically collected events. Use DebugView in the Firebase Console to verify events in real time, and follow naming conventions to keep your analytics data clean and queryable.

What you'll learn

  • How to initialize Firebase Analytics and call logEvent() with custom parameters
  • How to follow event naming conventions for consistent, queryable data
  • How to verify custom events using DebugView in the Firebase Console
  • How to set user properties for audience segmentation
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner7 min read10-15 minFirebase JS SDK v9+, all Firebase plans (Analytics is free)March 2026RapidDev Engineering Team
TL;DR

To track custom events in Firebase Analytics, call logEvent() from the Firebase modular SDK with an event name and optional parameters object. Custom events let you measure actions specific to your app beyond the automatically collected events. Use DebugView in the Firebase Console to verify events in real time, and follow naming conventions to keep your analytics data clean and queryable.

Tracking Custom Events in Firebase Analytics

Firebase Analytics automatically tracks events like page_view and first_visit, but most apps need custom events to measure business-specific actions such as purchases, sign-ups, or feature usage. This tutorial walks you through logging custom events with the modular SDK, defining meaningful parameters, verifying events in DebugView, and applying naming conventions that keep your analytics organized as your app grows.

Prerequisites

  • A Firebase project with a registered web app
  • Firebase JS SDK v9+ installed in your project
  • Basic familiarity with JavaScript or TypeScript
  • Access to the Firebase Console

Step-by-step guide

1

Initialize Firebase Analytics in your app

Import the Firebase app and analytics modules, then initialize analytics with your Firebase config. The getAnalytics() function returns an Analytics instance you will use for all logging calls. Call this once at app startup. Analytics is free on all Firebase plans and does not require the Blaze plan.

typescript
1import { initializeApp } from 'firebase/app';
2import { getAnalytics } from 'firebase/analytics';
3
4const firebaseConfig = {
5 apiKey: 'YOUR_API_KEY',
6 authDomain: 'YOUR_PROJECT.firebaseapp.com',
7 projectId: 'YOUR_PROJECT',
8 storageBucket: 'YOUR_PROJECT.appspot.com',
9 messagingSenderId: '123456789',
10 appId: '1:123456789:web:abc123',
11 measurementId: 'G-XXXXXXXXXX',
12};
13
14const app = initializeApp(firebaseConfig);
15const analytics = getAnalytics(app);

Expected result: Firebase Analytics is initialized and begins collecting automatic events like page_view and session_start.

2

Log a custom event with parameters

Use the logEvent() function to track any action you want to measure. The first argument is the event name (lowercase with underscores), and the second is an object of key-value parameters that provide context. Firebase recommends using their predefined event names when applicable (like 'purchase' or 'sign_up'), and custom names for app-specific actions.

typescript
1import { logEvent } from 'firebase/analytics';
2
3// Track when a user completes onboarding
4logEvent(analytics, 'onboarding_complete', {
5 method: 'email',
6 step_count: 4,
7});
8
9// Track a button click with context
10logEvent(analytics, 'cta_click', {
11 button_name: 'upgrade_plan',
12 page: 'pricing',
13});

Expected result: Custom events are queued and sent to Firebase Analytics within a few seconds.

3

Use recommended events for standard actions

Firebase provides a list of recommended event names with predefined parameter schemas. Using these events enables automatic reporting features in the Firebase Console, such as revenue tracking for 'purchase' events. Always prefer a recommended event over a custom name when the action matches.

typescript
1import { logEvent } from 'firebase/analytics';
2
3// Recommended: track a purchase with standard parameters
4logEvent(analytics, 'purchase', {
5 transaction_id: 'TXN_12345',
6 value: 29.99,
7 currency: 'USD',
8 items: [
9 { item_id: 'plan_pro', item_name: 'Pro Plan', price: 29.99 },
10 ],
11});
12
13// Recommended: track sign-up method
14logEvent(analytics, 'sign_up', {
15 method: 'Google',
16});

Expected result: Recommended events appear in specialized Analytics reports with pre-built dimensions and metrics.

4

Set user properties for segmentation

User properties are attributes you attach to users for audience segmentation. Unlike events, which track actions, user properties describe who the user is. Set them once and they persist across sessions. Use setUserProperties() to define custom properties like subscription tier or preferred language.

typescript
1import { setUserProperties } from 'firebase/analytics';
2
3// Set user properties after sign-in
4setUserProperties(analytics, {
5 plan_type: 'pro',
6 signup_source: 'landing_page',
7});

Expected result: User properties are attached to the user and can be used to filter audiences and reports in the Firebase Console.

5

Enable DebugView to verify events in real time

Events normally take 24-48 hours to appear in Firebase Analytics reports. DebugView shows events in real time, which is essential during development. Enable debug mode by installing the Google Analytics Debugger Chrome extension or by setting a URL parameter. Then open the Firebase Console, go to Analytics > DebugView to see events as they fire.

typescript
1// Option 1: Enable debug mode programmatically
2// Add this before initializing analytics
3(window as any).self.FIREBASE_ANALYTICS_DEBUG_MODE = true;
4
5// Option 2: Use URL parameter
6// Navigate to your app with ?debug_mode=true
7// Example: http://localhost:3000?debug_mode=true

Expected result: Events appear in the Firebase Console DebugView panel within seconds of being logged.

6

Build a reusable analytics helper

As your app grows, centralizing analytics calls in a helper module prevents code duplication and ensures consistent event naming. Create a typed wrapper around logEvent that enforces your event catalog. This makes it easy to add, rename, or audit events across the entire codebase.

typescript
1import { Analytics, logEvent } from 'firebase/analytics';
2
3type AppEvent =
4 | { name: 'onboarding_complete'; params: { method: string; step_count: number } }
5 | { name: 'cta_click'; params: { button_name: string; page: string } }
6 | { name: 'feature_used'; params: { feature: string; duration_ms?: number } };
7
8export function trackEvent(analytics: Analytics, event: AppEvent) {
9 logEvent(analytics, event.name, event.params);
10}
11
12// Usage
13trackEvent(analytics, {
14 name: 'feature_used',
15 params: { feature: 'dark_mode', duration_ms: 1200 },
16});

Expected result: All analytics calls are type-safe and centralized in one module for easy maintenance.

Complete working example

analytics.ts
1import { initializeApp } from 'firebase/app';
2import {
3 getAnalytics,
4 logEvent,
5 setUserProperties,
6 Analytics,
7} from 'firebase/analytics';
8
9// --- Firebase config ---
10const firebaseConfig = {
11 apiKey: 'YOUR_API_KEY',
12 authDomain: 'YOUR_PROJECT.firebaseapp.com',
13 projectId: 'YOUR_PROJECT',
14 storageBucket: 'YOUR_PROJECT.appspot.com',
15 messagingSenderId: '123456789',
16 appId: '1:123456789:web:abc123',
17 measurementId: 'G-XXXXXXXXXX',
18};
19
20const app = initializeApp(firebaseConfig);
21const analytics = getAnalytics(app);
22
23// --- Typed event catalog ---
24type AppEvent =
25 | { name: 'onboarding_complete'; params: { method: string; step_count: number } }
26 | { name: 'cta_click'; params: { button_name: string; page: string } }
27 | { name: 'feature_used'; params: { feature: string; duration_ms?: number } }
28 | { name: 'purchase'; params: { transaction_id: string; value: number; currency: string } };
29
30export function trackEvent(event: AppEvent): void {
31 logEvent(analytics, event.name, event.params);
32}
33
34// --- User properties ---
35export function identifyUser(props: {
36 plan_type: string;
37 signup_source?: string;
38}): void {
39 setUserProperties(analytics, props);
40}
41
42// --- Usage examples ---
43trackEvent({
44 name: 'onboarding_complete',
45 params: { method: 'email', step_count: 4 },
46});
47
48trackEvent({
49 name: 'cta_click',
50 params: { button_name: 'upgrade_plan', page: 'pricing' },
51});
52
53identifyUser({ plan_type: 'pro', signup_source: 'landing_page' });

Common mistakes when tracking Custom Events in Firebase Analytics

Why it's a problem: Using spaces, hyphens, or uppercase letters in event names

How to avoid: Always use lowercase with underscores: 'cta_click' not 'CTA-Click'. Firebase silently drops events with invalid names.

Why it's a problem: Expecting events to appear instantly in the main Analytics dashboard

How to avoid: Standard reports have a 24-48 hour delay. Use DebugView for real-time verification during development.

Why it's a problem: Logging too many unique event names instead of using parameters for variation

How to avoid: Use one event name with different parameter values. For example, log 'button_click' with a 'button_name' parameter instead of creating 'signup_button_click', 'upgrade_button_click', etc.

Why it's a problem: Forgetting the measurementId in the Firebase config

How to avoid: Without measurementId, getAnalytics() throws an error. Copy it from Firebase Console > Project Settings > General > Your Apps.

Best practices

  • Use Firebase's recommended event names (purchase, sign_up, login) when they match your action — this unlocks built-in reports
  • Keep custom event names short, descriptive, and lowercase with underscores
  • Limit parameters to the most useful dimensions — each event supports up to 25 custom parameters
  • Create a centralized analytics module so event names and parameters are defined in one place
  • Use DebugView during development to verify events fire correctly before deploying
  • Set user properties once after login to enable audience segmentation in reports
  • Never log personally identifiable information (PII) like email addresses or phone numbers in event parameters
  • Document your event catalog in a shared spreadsheet so the whole team uses consistent naming

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I need to add custom event tracking to my web app using Firebase Analytics v9 modular SDK. Show me how to initialize analytics, log custom events with parameters, use recommended events for purchases, and set user properties. Include a TypeScript helper for type-safe event logging.

Firebase Prompt

Set up Firebase Analytics in my web app. Initialize with getAnalytics, create a typed event catalog using discriminated unions, log custom events like onboarding_complete and cta_click with parameters, and add user properties for plan_type. Use Firebase modular SDK v9+ imports.

Frequently asked questions

How many custom events can I create in Firebase Analytics?

You can register up to 500 distinct custom event names per project. Each event can have up to 25 custom parameters. There is no limit on how many times you log the same event.

Are custom events free in Firebase Analytics?

Yes. Firebase Analytics, including custom events, is completely free with no usage caps. You only pay if you export data to BigQuery and run queries there.

Why do my events not appear in the Firebase Console?

Standard Analytics reports have a 24-48 hour processing delay. Use DebugView (Analytics > DebugView) to see events in real time. Make sure debug mode is enabled on your device.

What is the difference between an event parameter and a user property?

Event parameters describe a specific action (like which button was clicked). User properties describe the user themselves (like their subscription plan) and persist across sessions until changed.

Can I rename or delete a custom event after logging it?

You cannot rename or delete events from historical data. You can stop logging an event and create a new one with a different name. Unused events stop appearing in reports after 60 days of inactivity.

Should I use Google Analytics 4 or Firebase Analytics?

They are the same underlying system. Firebase Analytics feeds into Google Analytics 4 automatically. Use the Firebase SDK in your app and view data in either the Firebase Console or the GA4 interface.

Can RapidDev help implement a custom analytics tracking strategy?

Yes. RapidDev can help you design an event taxonomy, implement type-safe tracking across your app, set up BigQuery exports for advanced analysis, and build custom dashboards for your team.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.