Skip to content

feat: Global activity tracking, robust error handling, and Firebase (Crashlytics / Analytics / Performance)#97

Open
PremSharma-Intelegencia wants to merge 1 commit intofleetbase:mainfrom
blockalicious-io:feat/firebase-crashlytics-
Open

feat: Global activity tracking, robust error handling, and Firebase (Crashlytics / Analytics / Performance)#97
PremSharma-Intelegencia wants to merge 1 commit intofleetbase:mainfrom
blockalicious-io:feat/firebase-crashlytics-

Conversation

@PremSharma-Intelegencia

This PR introduces a comprehensive observability layer for the React Native app, combining crash reporting, non-fatal error tracking, user activity breadcrumbs, and performance/screen analytics, all with minimal app-level instrumentation.


What’s new

Robust error boundaries and crash reporting

  • Introduces a new ErrorBoundary component with:
    • A safe, RN-only fallback UI (no Tamagui dependency in error paths).
    • Automatic logging of non-fatal errors to Firebase Crashlytics (modular API).
  • Enriches Crashlytics reports with:
    • App version and build
    • Component stack
    • Likely source component
    • Recent user activity breadcrumbs

Comprehensive activity tracking system

  • New primitives:
    • ActivityTrackerContext
    • TrackedView wrapper
    • useActivityTracker hook
  • New activityInterceptor utilities providing:
    • Bounded, debounced breadcrumb buffer
    • Analytics event logging
    • Function call and interaction tracking
    • Crashlytics breadcrumb synchronization
    • Explicit force-sync on crash or fatal error

Global interception (low-touch instrumentation)

Automatically captures interactions without invasive app changes by attempting to patch:

  • React.createElement
  • JSX runtime
  • React Native Pressability

This enables consistent tracking of:

  • User interactions
  • Navigation and screens
  • Key handler invocations

Firebase helper utilities

  • Two-phase error handling:
    1. setupEarlyErrorHandler
      • Runs immediately at module load
      • Captures and queues errors before Firebase is ready
    2. initializeCrashlytics
      • Flushes queued errors
      • Hooks console.log, console.warn, and console.error into Crashlytics
  • logScreenView helper:
    • Starts and stops Performance traces
    • Logs screen views to Analytics
    • Attaches screen metadata to Crashlytics

App lifecycle integration

  • setupEarlyErrorHandler runs at module scope
  • initializeCrashlytics runs in AppContent useEffect after mount
  • App root is wrapped with:
    • ErrorBoundary
    • ActivityTrackerProvider
    • TrackedView
  • index.native.tsx:
    • Enables global tracking before AppRegistry.registerComponent
    • Calls enableGlobalTracking() early for full coverage

Platform and build changes

Android

  • Adds Firebase Crashlytics and Performance plugins
  • Updates:
    • android/build.gradle (classpath)
    • app/build.gradle (plugins and dependencies)
  • Adds:
    • firebase-crashlytics
    • firebase-perf
  • Minor cleanup to signingConfig formatting

iOS

  • Podfile updates:
    • Framework linkage
    • header_search_paths
  • AppDelegate.swift initializes Firebase via FirebaseApp.configure()
  • Xcode project updates:
    • GoogleService-Info.plist inclusion
    • RNFirebase build phases
  • Updated Podfile.lock

Tooling and configuration

  • Adds @react-native-firebase packages:
    • app
    • analytics
    • crashlytics
    • perf
  • Babel:
    • Enables experimental JSX transform
    • Adds JSX transform plugin
  • TypeScript:
    • Extends React Native TS config
    • Enables "jsx": "react-native"
    • Enables strict mode and other safe defaults
  • New source files:
    • ErrorBoundary
    • ActivityTrackerContext
    • use-activity-tracker
    • activityInterceptor
    • firebaseHelper
  • Updated:
    • .gitignore
    • yarn.lock
    • Gemfile.lock
    • Podfile.lock

Migration and verification steps

  1. Install dependencies

    yarn install --immutable 
  2. iOS pods

    cd ios && pod install
  3. Add platform config files (if missing):

    • ios/GoogleService-Info.plist
    • android/app/google-services.json
  4. Ensure Android signing environment variables or Gradle properties are set for release builds

  5. Clean and rebuild (Xcode and Gradle)

  6. Verify:

    • App boots cleanly even when rendering errors (ErrorBoundary fallback)
    • Activity tracking emits Analytics events
    • Breadcrumbs appear in Crashlytics
    • Queued early errors flush on first initializeCrashlytics() call

Debugging

To enable internal tracker logs in development:

global.__ACTIVITY_TRACKER_DEBUG__ = true

…Crashlytics/Analytics/Perf)

- Add robust error boundary and crash reporting:
   - New ErrorBoundary component that renders a safe RN-only fallback UI and logs non-fatal errors to Firebase Crashlytics (modular API).
   - Ensures Crashlytics attributes (app version, build, component stack, likely source component) and records errors/breadcrumbs.

- Add comprehensive activity tracking system:
   - New ActivityTrackerContext + TrackedView wrapper and useActivityTracker hook.
   - New activityInterceptor utilities implementing breadcrumb buffer, analytics logging, function call tracking, and Crashlytics sync.
   - Global interception: attempts to patch React.createElement, JSX runtime, and RN Pressability to automatically wrap interaction handlers and capture user interactions without invasive app changes.
   - Debounced, bounded breadcrumb storage and explicit force-sync for crash-time flush.

- Add Firebase helper utilities:
   - Two-phase error handling: setupEarlyErrorHandler (immediate, queues errors) and initializeCrashlytics (flush queued errors and hook console -> Crashlytics).
   - logScreenView helper starts/stops Performance traces, logs Analytics and Crashlytics attributes.
   - Console interception to forward logs/warns/errors to Crashlytics once available.

- Wire tracking and error handling into app lifecycle:
   - Call setupEarlyErrorHandler early (module-level).
   - Call initializeCrashlytics in AppContent useEffect after app mount.
   - Wrap AppContent with ErrorBoundary and ActivityTrackerProvider/TrackedView.
   - index.native.tsx enables global tracking before AppRegistry.registerComponent and calls enableGlobalTracking().

- Platform and build changes for Firebase:
   - Android: add Crashlytics & Performance plugins, apply plugins in app/build.gradle, add dependencies (firebase-crashlytics, firebase-perf), update classpath in android/build.gradle, minor signingConfig formatting fixes.
   - iOS: Podfile changes for framework linkage and header_search_paths; AppDelegate.swift initializes FirebaseApp.configure(); project.pbxproj updated to include GoogleService-Info.plist and RNFB build phases; Podfile.lock updated.

- Tooling / config changes:
   - Add @react-native-firebase packages to package.json (app, analytics, crashlytics, perf).
   - Babel: enable experimental JSX transform option and add JSX transform plugin.
   - TypeScript: extend RN TS config, enable "jsx": "react-native", esModuleInterop, strict mode and other safe defaults.
   - Add new source files: ErrorBoundary, ActivityTrackerContext, use-activity-tracker, activityInterceptor, firebaseHelper.
   - Update .gitignore, lockfiles (yarn.lock, Gemfile.lock, Podfile.lock) to reflect dependency changes.

- Notes / migration steps:
   1. Install new deps: yarn install
   2. iOS: cd ios && pod install
   3. Add platform config files: place GoogleService-Info.plist (iOS) and google-services.json (Android) into the project if not already present.
   4. Ensure Android signing env vars or gradle properties for release keystore are set.
   5. Clean builds (Xcode / Gradle) and verify:
       - App starts without Tamagui dependency in error path (ErrorBoundary fallback).
       - Activity tracking logs events to Analytics and breadcrumbs are sent to Crashlytics.
       - Crashlytics receives queued errors on first initializeCrashlytics() call.
   6. For debugging: set global.__ACTIVITY_TRACKER_DEBUG__ = true in JS dev console to enable internal logs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants