0
0
Firebasecloud~5 mins

Custom events in Firebase - Commands & Configuration

Choose your learning style9 modes available
Introduction
Custom events let you track specific actions users take in your app that are not covered by default events. This helps you understand user behavior better and improve your app experience.
When you want to know how many users clicked a special button in your app.
When you want to track when users complete a level in a game.
When you want to measure how often users share content from your app.
When you want to see how many users add items to a wishlist.
When you want to track custom user actions like form submissions or video plays.
Commands
This command logs a custom event named 'add_to_wishlist' with details about the item. It helps track when users add items to their wishlist.
Terminal
firebase analytics logEvent add_to_wishlist {"item_id":"1234", "item_name":"blue_shirt"}
Expected OutputExpected
Event logged: add_to_wishlist
This command retrieves the list of recent events logged in your Firebase project to verify your custom event was recorded.
Terminal
firebase analytics getEvents
Expected OutputExpected
Events: - add_to_wishlist - app_open - screen_view
Key Concept

If you remember nothing else from this pattern, remember: custom events let you track any user action you care about beyond default events.

Common Mistakes
Using event names with spaces or special characters
Firebase requires event names to be alphanumeric and underscores only, otherwise the event won't be logged.
Use only letters, numbers, and underscores in event names, like 'add_to_wishlist'.
Logging too many custom events with large payloads
This can slow down your app and exceed Firebase limits, causing data loss or delays.
Keep event parameters small and only log important custom events.
Summary
Use 'firebase analytics logEvent' to send custom events with parameters.
Verify events with 'firebase analytics getEvents' to see what was logged.
Choose simple event names and keep event data small for best results.