feat: Global activity tracking, robust error handling, and Firebase (Crashlytics / Analytics / Performance)#97
Open
PremSharma-Intelegencia wants to merge 1 commit intofleetbase:mainfrom
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ErrorBoundarycomponent with:Comprehensive activity tracking system
ActivityTrackerContextTrackedViewwrapperuseActivityTrackerhookactivityInterceptorutilities providing:Global interception (low-touch instrumentation)
Automatically captures interactions without invasive app changes by attempting to patch:
React.createElementPressabilityThis enables consistent tracking of:
Firebase helper utilities
setupEarlyErrorHandlerinitializeCrashlyticsconsole.log,console.warn, andconsole.errorinto CrashlyticslogScreenViewhelper:App lifecycle integration
setupEarlyErrorHandlerruns at module scopeinitializeCrashlyticsruns inAppContentuseEffectafter mountErrorBoundaryActivityTrackerProviderTrackedViewindex.native.tsx:AppRegistry.registerComponentenableGlobalTracking()early for full coveragePlatform and build changes
Android
android/build.gradle(classpath)app/build.gradle(plugins and dependencies)firebase-crashlyticsfirebase-perfsigningConfigformattingiOS
header_search_pathsAppDelegate.swiftinitializes Firebase viaFirebaseApp.configure()GoogleService-Info.plistinclusionPodfile.lockTooling and configuration
@react-native-firebasepackages:appanalyticscrashlyticsperf"jsx": "react-native"strictmode and other safe defaultsErrorBoundaryActivityTrackerContextuse-activity-trackeractivityInterceptorfirebaseHelper.gitignoreyarn.lockGemfile.lockPodfile.lockMigration and verification steps
Install dependencies
iOS pods
Add platform config files (if missing):
ios/GoogleService-Info.plistandroid/app/google-services.jsonEnsure Android signing environment variables or Gradle properties are set for release builds
Clean and rebuild (Xcode and Gradle)
Verify:
initializeCrashlytics()callDebugging
To enable internal tracker logs in development: