Firebase Analytics
Google Analytics for Firebase provides free, unlimited reporting on up to 500 distinct events. It's the heart of Firebase's growth and engagement features.
1. Basic Logging
Firebase automatically logs many events, but you can also log custom events for specific user actions.
import { getAnalytics, logEvent } from "firebase/analytics";
const analytics = getAnalytics();
// Log a custom event
logEvent(analytics, 'tutorial_completed', {
tutorial_name: 'Firebase Intro',
difficulty: 'Beginner'
});
2. Tracking User Properties
User properties allow you to segment your users by fixed attributes like language, favorite genre, or loyalty level.
import { setUserProperties } from "firebase/analytics";
setUserProperties(analytics, { favorite_color: 'blue' });
3. DebugView
While developing, you can see your events in real-time in the Firebase Console under the "DebugView" tab.
Privacy Note: Always ensure you are compliant with local data privacy laws (like GDPR) when collecting analytics data.