Develop

Firebase sample overview

Updated: May 11, 2026

Overview

This sample demonstrates how to integrate Firebase Analytics and Crashlytics into a Meta Quest Unity application. It shows how to initialize Firebase services, log custom analytics events with typed parameters, and record crash data. You control data collection settings through a runtime debug UI.

What you will learn

  • Initialize Firebase services asynchronously in Unity and verify dependency resolution
  • Log custom analytics events with int, float, and string parameters using Firebase Analytics
  • Record crash logs, non-fatal exceptions, and custom metadata using Firebase Crashlytics
  • Control analytics and crash reporting collection at runtime
  • Configure user IDs, user properties, and session timeouts for Firebase services

Requirements

  • A Meta Quest device
  • A Unity development environment configured for Android builds
For SDK versions, Firebase setup, and detailed build prerequisites, see the sample README.

Get started

Clone or download the Unity-StarterSamples repository from GitHub. Open the project in Unity, then navigate to Assets/StarterSamples/Usage/Tools/ and open Firebase.unity. Before building, import the Firebase Unity SDK packages and replace the placeholder google-services.json with your configuration file from Firebase Console. Enable the Firebase sample through Meta > Samples > Firebase > Enable Firebase Sample. Build and deploy to your Quest device using Meta Quest Developer Hub or Unity’s build tools.

Explore the sample

The sample uses a debug UI panel system to expose Firebase APIs at runtime. Press the B button on your controller to toggle UI visibility.
File / SceneWhat it demonstratesKey concepts
Firebase.unity
Complete Firebase integration scene
OVRCameraRig prefab for VR tracking, DebugUIBuilder for runtime panels, and three Firebase GameObjects (StartCrashlytics, SampleUI, AnalyticsUI)
StartCrashlytics.cs
Firebase SDK initialization
Async dependency verification, continuation-based flow control, app instance field to prevent garbage collection
AnalyticsUI.cs
Firebase Analytics API usage
Custom event logging with typed parameters, user ID and property assignment, analytics collection control, session timeout configuration
SampleUI.cs
Firebase Crashlytics API usage
Crash log recording, non-fatal exception logging, custom key-value metadata via SetCustomKey(), user ID tracking, collection control via IsCrashlyticsCollectionEnabled property
FirebaseEnabler.cs (Editor)
Conditional compilation setup
Scripting define symbol management for Android builds, menu integration for enabling Firebase support

Runtime behavior

When you run the sample with Firebase enabled, you see four debug UI panes floating over a gray ground plane. The center pane contains Crashlytics controls for logging messages, recording exceptions, and forcing test crashes. The right pane shows text input fields used by Crashlytics methods. The left pane contains Analytics controls for managing data collection, session configuration, and user properties. The extra pane provides custom event logging with dynamic parameter fields where you can add int, float, or string parameters before sending an event.

Key concepts

Async Firebase initialization

The sample initializes Firebase using a dependency verification pattern. Notice how StartCrashlytics.cs calls FirebaseApp.CheckAndFixDependenciesAsync() in the Start() method and chains a continuation to check the DependencyStatus. The app instance is stored as an instance field to prevent garbage collection during the app lifecycle.
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
  if (task.Result == DependencyStatus.Available) {
    app = FirebaseApp.DefaultInstance;
  }
});
This is a simplified excerpt. See the complete initialization flow with error handling in Assets/StarterSamples/Usage/Tools/Firebase/StartCrashlytics.cs.

Custom analytics events with typed parameters

The sample logs custom analytics events using typed parameter arrays. AnalyticsUI.cs builds parameter arrays dynamically based on user input. The code demonstrates how to create Parameter objects with different data types and pass them to FirebaseAnalytics.LogEvent(). Notice how the dynamic parameter system uses reflection on DebugUIBuilder internals to add and remove UI fields at runtime.
See the parameter construction and logging implementation in Assets/StarterSamples/Usage/Tools/Firebase/AnalyticsUI.cs.

Crash reporting with custom metadata

The sample demonstrates how to attach context to crash reports using custom key-value pairs and user IDs. SampleUI.cs shows how to call Crashlytics.SetCustomKey() and Crashlytics.SetUserId() to tag crash reports with identifying information. The sample also includes a deliberate crash trigger using unsafe pointer dereferencing for testing crash reporting integration.
See the Crashlytics metadata methods in Assets/StarterSamples/Usage/Tools/Firebase/SampleUI.cs.

Conditional compilation for optional dependencies

The sample uses the OVR_SAMPLES_ENABLE_FIREBASE scripting define symbol to guard all Firebase code behind conditional compilation. The sample compiles without errors when the Firebase SDK packages are not present. The editor script FirebaseEnabler.cs manages this define symbol through a menu interface, setting it only for the Android build target.
See the define symbol management in Assets/StarterSamples/Core/Tools/Firebase/Editor/FirebaseEnabler.cs.

Extend the sample

  • Add Firebase Remote Config: Extend the debug UI to fetch and display remote configuration values, letting you modify app behavior without deploying a new build.
  • Integrate Firebase Cloud Messaging: Add push notification listeners and UI indicators to handle notifications on Quest devices.
  • Correlate analytics with crash data: Combine custom analytics events with Crashlytics custom keys to identify user behavior patterns leading to crashes.