Setup & Analytics

Firebase is a suite of backend services from Google — authentication, databases, messaging, storage, analytics — that lets an app like RecipeBox get server-side features without building and hosting a custom backend. This lesson covers the one-time setup every Firebase feature depends on, plus the first library we'll add: Firebase Analytics.

Creating a Firebase Project

  1. Go to the Firebase Console and create a new project (e.g. "RecipeBox").
  2. Add an Android app inside that project, entering RecipeBox's application ID (the applicationId from build.gradle).
  3. Download the generated google-services.json file and place it in the app module's root folder (next to build.gradle, inside app/).
Keep it out of public repositories: google-services.json identifies your specific Firebase project and contains API keys tied to it. If RecipeBox's source code lives in a public repository, add this file to .gitignore rather than committing it — treat it the same way you'd treat any other credential file, even though Google documents it as safe to ship inside a compiled APK.

Adding the Google Services Gradle Plugin

Firebase relies on a Gradle plugin that reads google-services.json and wires the right configuration into your build. It's declared at the project level and applied at the app module level:

// Project-level build.gradle
plugins {
    id 'com.android.application' version '8.4.0' apply false
    id 'com.google.gms.google-services' version '4.4.2' apply false
}
// App-level build.gradle
plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}

The Firebase Bill of Materials (BoM)

Firebase ships dozens of libraries (Analytics, Auth, Firestore, and more), each with its own version number. Rather than picking a version for each one individually and risking mismatches, add the Firebase BoM once — it pins every Firebase library you add afterward to versions known to work together:

dependencies {
    implementation platform('com.google.firebase:firebase-bom:33.1.2')
    implementation 'com.google.firebase:firebase-analytics'
}
Explanation: Notice there's no version number after firebase-analytics — the BoM supplies it. Every other Firebase library added later in this section (Auth, Firestore, Realtime DB, FCM, Storage) follows this same pattern: no per-library version needed once the BoM is in place.

Firebase Analytics: Automatic + Custom Events

Once firebase-analytics is added, Firebase automatically starts logging a set of standard events — app opens, screen views, first opens — with zero extra code. On top of that, you can log your own custom events for anything specific to RecipeBox:

// After the user taps "Save Recipe"
FirebaseAnalytics analytics = FirebaseAnalytics.getInstance(this);

Bundle params = new Bundle();
params.putString("category", recipe.getCategory());

analytics.logEvent("recipe_saved", params);
Explanation:
  • logEvent(name, params) is the one method used for every custom event — the event name and a Bundle of parameters describing it.
  • Here, logging recipe_saved with the recipe's category lets you later see, in the Firebase Console, which categories (e.g. "Desserts" vs "Soups") users save most often.
  • Event names should be short, consistent, snake_case identifiers — treat them like a small vocabulary you design deliberately, since renaming an event later fragments your historical data.

Verifying Events with DebugView

Analytics events are normally batched and can take hours to appear in standard Firebase Console reports — far too slow for day-to-day development. Enabling DebugView shows events from your test device almost immediately:

// From a terminal, with the device/emulator connected via adb
adb shell setprop debug.firebase.analytics.app com.recipebox

With that property set, open Analytics → DebugView in the Firebase Console and trigger the "Save Recipe" flow on the device — the recipe_saved event (with its category parameter) should appear within seconds.

What's Coming in the Firebase Section

ProductUsed forCovered in
AuthenticationSign-up/sign-in so each user has their own accountFirebase Auth (Java)
Cloud FirestoreStoring structured recipe data per user, syncing across devicesandroid-firestore-java.php
Realtime DatabaseAn alternative, older real-time data storeandroid-realtimedb-java.php
Cloud Messaging (FCM)Push notifications (e.g. "your shared recipe was liked")android-fcm-java.php
StorageHosting recipe photos/videos in the cloudandroid-firebase-storage-java.php
With the project connected and Analytics logging events, the next step is giving each RecipeBox user their own account in Firebase Auth (Java).