0
0
Android Kotlinmobile~20 mins

Firebase Analytics in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase Analytics Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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
A
analytics.logEvent("purchase_complete") {
  param("item_id", "sku123")
  param("price", 9.99)
}
Banalytics.logEvent("purchase_complete", mapOf("item_id" to "sku123", "price" to 9.99))
C
val bundle = Bundle().apply {
  putString("item_id", "sku123")
  putDouble("price", 9.99)
}
analytics.logEvent("purchase_complete", bundle)
Danalytics.logEvent("purchase_complete", Bundle().putString("item_id", "sku123"))
Attempts:
2 left
💡 Hint
Remember that Firebase Analytics expects a Bundle object for event parameters in Kotlin.
lifecycle
intermediate
1: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?
AIn the <code>Application</code> class <code>onCreate()</code> method
BInside the <code>onCreate()</code> method of the main <code>Activity</code>
CInside the <code>onStart()</code> method of every <code>Activity</code>
DRight before logging each event
Attempts:
2 left
💡 Hint
Think about initializing once for the whole app lifecycle.
📝 Syntax
advanced
1: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
Aanalytics.setUserProperty("favorite_genre", value = "sci-fi")
Banalytics.setUserProperty("favorite_genre", "sci-fi")
Canalytics.setUserProperty("favorite_genre" to "sci-fi")
Danalytics.setUserProperty(name = "favorite_genre", "sci-fi")
Attempts:
2 left
💡 Hint
Check the method signature for setUserProperty in Firebase Analytics Kotlin API.
navigation
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?
Aanalytics.setCurrentScreen(this, "HomeScreen", "MainActivity")
B
analytics.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW) {
  param(FirebaseAnalytics.Param.SCREEN_NAME, "HomeScreen")
}
C
analytics.logEvent("screen_view", Bundle().apply {
  putString("screen_name", "HomeScreen")
})
Danalytics.setCurrentScreen(this, "HomeScreen", null)
Attempts:
2 left
💡 Hint
Check the official Firebase method for setting current screen with activity context.
🔧 Debug
expert
2: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?
AYou did not call <code>FirebaseApp.initializeApp(context)</code> explicitly in your Application class
BYou logged events before initializing Firebase Analytics instance
CYou forgot to add the Firebase Analytics dependency in your build.gradle file
DYou used event names longer than 40 characters or with invalid characters
Attempts:
2 left
💡 Hint
Firebase Analytics enforces naming rules for events.