Skip to content

Firebase Analytics: Track User Behavior & App Performance Events

DodaTech Updated 2026-06-28 5 min read

In this tutorial, you will learn about Firebase Analytics: Track User Behavior & App Performance Events. We cover key concepts, practical examples, and best practices to help you master this topic.

Firebase Analytics is a free, unlimited analytics solution that tracks user behavior, screens, events, and conversions across web and mobile platforms with Google Analytics integration.

What You'll Learn

How to implement Firebase Analytics, log custom events, track screen views, set user properties, build audiences, measure conversions, and export data to BigQuery for custom analysis.

Why It Matters

Understanding user behavior drives product decisions. DodaTech uses Firebase Analytics to track which threat detection features users engage with most, identify drop-off points in the scan flow, and measure the impact of new features.

Real-World Use

A product manager wants to know: how many users complete a full scan? What percentage see a threat detection? How many upgrade after a threat is found? Firebase Analytics answers all these questions.

flowchart LR
    A["User Action\nStart Scan"] --> B["Log Event\nscan_started"]
    B --> C["Log Event\nscan_completed"]
    C --> D{"Threat Found?"}
    D -->|Yes| E["Log Event\nthreat_detected"]
    D -->|No| F["Log Event\nscan_clean"]
    E --> G["Log Event\nthreat_details_viewed"]
    G --> H["Log Event\nupgrade_viewed"]
    style A fill:#dbeafe,stroke:#2563eb
    style B fill:#fef3c7,stroke:#d97706
    style C fill:#bbf7d0,stroke:#16a34a

Logging Events

import { getAnalytics, logEvent } from "firebase/analytics";

const analytics = getAnalytics();

// Log a custom event
function trackScanCompleted(scanId, threatCount) {
  logEvent(analytics, "scan_completed", {
    scan_id: scanId,
    threat_count: threatCount,
    duration_seconds: calculateDuration()
  });
  console.log("Analytics event: scan_completed");
}

// Log a recommended event
function trackPurchase(productId, price, currency) {
  logEvent(analytics, "purchase", {
    transaction_id: "TXN_" + Date.now(),
    value: price,
    currency: currency,
    items: [{ item_id: productId, item_name: "Pro Subscription" }]
  });
  console.log("Analytics event: purchase");
}

Screen Tracking

// Track screen views automatically with Firebase SDK
// For manual screen tracking:
import { logEvent } from "firebase/analytics";
import { getAnalytics } from "firebase/analytics";

function trackScreen(screenName, screenClass) {
  logEvent(getAnalytics(), "screen_view", {
    firebase_screen: screenName,
    firebase_screen_class: screenClass || screenName
  });
  console.log("Screen tracked:", screenName);
}

// Usage
trackScreen("Dashboard", "DashboardActivity");
trackScreen("ScanResults");
// Expected output: Screen tracked: Dashboard
//                  Screen tracked: ScanResults

User Properties

import { getAnalytics, setUserProperties } from "firebase/analytics";

const analytics = getAnalytics();

// Set user properties for segmentation
function setUserSegmentation(user) {
  setUserProperties(analytics, {
    subscription_tier: user.subscriptionTier || "free",
    device_count: user.deviceCount?.toString() || "0",
    days_since_install: getDaysSinceInstall().toString(),
    last_threat_severity: user.lastThreatSeverity || "none"
  });
  console.log("User properties set");
}

// Later, in Analytics, segment by:
// - subscription_tier: "free" vs "pro"
// - device_count: "1-3" vs "4+"
// Filter events by these properties

Conversion Events

// Mark events as conversions in Firebase Console
// Analytics > Events > Toggle "Mark as conversion"

// Key conversion events for an antivirus app:
// - scan_completed (engagement)
// - threat_detected (value)
// - upgrade_viewed (intent)
// - purchase (revenue)
// - subscription_cancelled (churn risk)

function trackUpgradeViewed(planName) {
  logEvent(getAnalytics(), "upgrade_viewed", {
    plan_name: planName,
    price: planName === "pro" ? 9.99 : 4.99
  });
  console.log("Upgrade view tracked");
}

BigQuery Export

// Enable BigQuery export in Firebase Console:
// Analytics > BigQuery > Link to BigQuery

// Then query with SQL:
// SELECT
//   event_name,
//   COUNT(*) as event_count,
//   COUNT(DISTINCT user_pseudo_id) as unique_users
// FROM `durga-antivirus.analytics_123456789.events_*`
// WHERE event_name IN ('scan_completed', 'threat_detected', 'purchase')
//   AND _TABLE_SUFFIX BETWEEN '20260601' AND '20260628'
// GROUP BY event_name
// ORDER BY event_count DESC

// Expected BigQuery result:
// scan_completed        -- 45,230 events, 12,450 users
// threat_detected       -- 3,201 events, 2,890 users
// purchase              -- 890 events, 890 users

Common Mistakes

1. Logging Personally Identifiable Information

Never log emails, phone numbers, or user names. Firebase Analytics terms prohibit PII. Use user properties with anonymized IDs.

2. Not Limiting Custom Event Volume

Firebase Analytics has a limit of 500 distinct event types. Use recommended events where possible and avoid creating events for minor interactions.

3. Forgetting to Test Events in Debug Mode

Events may not appear in real-time dashboard. Enable debug mode: firebase.analytics().setAnalyticsCollectionEnabled(true) and use DebugView in Firebase Console.

4. Over-Reporting Screen Views

Logging screen_view on every component mount inflates metrics. Track meaningful screens (full-page views) not UI component visibility.

5. Ignoring Analytics Implementation in Privacy-First Mode

Users may opt out of analytics. Check analytics().isCollectionEnabled() and respect user privacy preferences.

Practice Questions

  1. What is the difference between events and user properties?
  2. How do you mark an event as a conversion?
  3. How do you export Firebase Analytics data for custom analysis?
  4. What information should you never log in Analytics?

Answers:

  1. Events measure user actions (scan, purchase). User properties describe user attributes (tier, device count). Use events for counting, properties for segmentation.
  2. In Firebase Console > Analytics > Events, toggle "Mark as conversion" for the event. Conversion events appear in the Conversions report.
  3. Link Firebase project to BigQuery. Data exports daily as sharded tables. Run SQL queries for custom analysis.
  4. Never log PII (email, phone, SSN), passwords, authentication tokens, or any data that can identify individual users.

Challenge: Implement Analytics for a security app: log scan_started/scan_completed/threat_detected events, set user properties (subscription tier, device count), mark scan_completed as conversion, and write a BigQuery query to calculate the scan completion rate.

FAQ

Is Firebase Analytics really free?

Yes, Firebase Analytics is free with unlimited event reporting. There is no cost for collecting or viewing analytics data.

How long does it take for events to appear in reports?

Real-time events appear within seconds in the DebugView. Standard reports have a 24-48 hour processing delay.

Can I use Firebase Analytics without Google Analytics?

Firebase Analytics uses Google Analytics under the hood. When you set up Analytics, it creates a Google Analytics 4 property. You cannot separate them.

How do I handle user opt-out from analytics?

Call setAnalyticsCollectionEnabled(false) when the user opts out. Respect platform-specific privacy requirements (GDPR, CCPA, ATT on iOS).

Can I retroactively change event parameters?

No, event schemas are locked once received. Add new parameters in new versions of your app, but existing data retains original parameters.

Mini Project

Implement Analytics for a security dashboard app: track 5 key events (app_open, scan_started, scan_completed, threat_detected, purchase), set 3 user properties (tier, device count, region), create a conversion funnel in Analytics, and export to BigQuery for retention analysis.

What's Next

Firebase Crashlytics — track and fix app crashes with real-time reporting.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro