Challenge - 5 Problems
Firebase Analytics Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Logging a Custom Event with Parameters
You want to log a custom event named "purchase_complete" with parameters item_id and price using Firebase Analytics in Kotlin. Which code snippet correctly logs this event?
Android Kotlin
val analytics = Firebase.analytics // Log event here
Attempts:
2 left
💡 Hint
Remember that Firebase Analytics expects a Bundle object for event parameters in Kotlin.
✗ Incorrect
Firebase Analytics in Kotlin requires event parameters to be passed as a Bundle object. Option C correctly creates a Bundle with the parameters and logs the event. Option C uses a Kotlin DSL style which is not supported. Option C tries to pass a Map which is invalid. Option C passes a Bundle but only with one parameter and incorrectly chains putString without storing the Bundle.
❓ lifecycle
intermediate1:30remaining
When to Initialize Firebase Analytics
In an Android app using Kotlin, where is the best place to initialize Firebase Analytics to ensure it is ready for logging events throughout the app?
Attempts:
2 left
💡 Hint
Think about initializing once for the whole app lifecycle.
✗ Incorrect
Initializing Firebase Analytics in the Application class's onCreate() method ensures it is set up once when the app starts and is available throughout the app lifecycle. Initializing in each Activity or before each event is inefficient and error-prone.
📝 Syntax
advanced1:30remaining
Correct Syntax for Setting User Property
Which Kotlin code snippet correctly sets a user property named "favorite_genre" with value "sci-fi" using Firebase Analytics?
Android Kotlin
val analytics = Firebase.analytics // Set user property here
Attempts:
2 left
💡 Hint
Check the method signature for setUserProperty in Firebase Analytics Kotlin API.
✗ Incorrect
The correct method call is setUserProperty(name: String, value: String?). Option B matches this signature. Option B uses a Pair which is invalid. Option B uses a named argument 'value' which is allowed but the method signature does not define a named parameter 'value' explicitly, so it may cause an error. Option B mixes named and positional arguments incorrectly.
advanced
2:00remaining
Tracking Screen Views Correctly
You want to track screen views in your Android app using Firebase Analytics. Which approach correctly logs the screen name "HomeScreen" when the user navigates to it?
Attempts:
2 left
💡 Hint
Check the official Firebase method for setting current screen with activity context.
✗ Incorrect
Option A correctly calls setCurrentScreen with the activity context, screen name, and screen class override. Option A is deprecated and may cause runtime errors. Option A uses a Kotlin DSL style which is not supported. Option A logs a custom event but does not set the current screen properly.
🔧 Debug
expert2:30remaining
Diagnosing Missing Analytics Events
You notice that some custom events are not appearing in Firebase Analytics dashboard after logging them in your Kotlin app. Which of the following is the MOST likely cause?
Attempts:
2 left
💡 Hint
Firebase Analytics enforces naming rules for events.
✗ Incorrect
Firebase Analytics requires event names to be 40 characters or less and only contain alphanumeric characters and underscores. Using invalid event names causes events to be dropped silently. Option D would cause compile errors. Option D usually causes runtime errors. Option D is not required if Firebase is configured properly via google-services plugin.