Bird
Raised Fist0
Android Kotlinmobile~10 mins

Firebase Analytics in Android Kotlin - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize Firebase Analytics in an Android Kotlin app.

Android Kotlin
val firebaseAnalytics = FirebaseAnalytics.[1](this)
Drag options to blanks, or click blank then click option'
AgetInstance
Binitialize
Ccreate
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'initialize' instead of 'getInstance' causes a compile error.
Trying to call 'create' or 'start' methods which do not exist.
2fill in blank
medium

Complete the code to log a custom event named "share_image" with Firebase Analytics.

Android Kotlin
val bundle = Bundle().apply {
  putString(FirebaseAnalytics.Param.METHOD, "[1]")
}
firebaseAnalytics.logEvent("share_image", bundle)
Drag options to blanks, or click blank then click option'
Abluetooth
Bsms
Csocial
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid method name that is not a string.
Forgetting to put the parameter inside the bundle.
3fill in blank
hard

Fix the error in the code to set the user ID for Firebase Analytics.

Android Kotlin
firebaseAnalytics.[1]("user_123")
Drag options to blanks, or click blank then click option'
AsetUserId
BsetUserID
CsetUser
DuserId
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'setUserID' with uppercase 'ID' causes a method not found error.
Using 'setUser' or 'userId' which are not valid methods.
4fill in blank
hard

Fill both blanks to create a bundle with a parameter for item ID and log an event named "select_content".

Android Kotlin
val bundle = Bundle().apply {
  putString(FirebaseAnalytics.Param.[1], "12345")
}
firebaseAnalytics.logEvent("[2]", bundle)
Drag options to blanks, or click blank then click option'
AITEM_ID
BCONTENT_TYPE
Cselect_content
Dview_item
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'CONTENT_TYPE' instead of 'ITEM_ID' for the parameter key.
Logging the wrong event name like 'view_item' instead of 'select_content'.
5fill in blank
hard

Fill all three blanks to create a bundle with item name and content type, then log a "view_item" event.

Android Kotlin
val bundle = Bundle().apply {
  putString(FirebaseAnalytics.Param.[1], "Sunglasses")
  putString(FirebaseAnalytics.Param.[2], "[3]")
}
firebaseAnalytics.logEvent("view_item", bundle)
Drag options to blanks, or click blank then click option'
AITEM_NAME
BCONTENT_TYPE
Caccessories
DITEM_ID
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up parameter keys like using 'ITEM_ID' instead of 'ITEM_NAME'.
Using an incorrect content type value.

Practice

(1/5)
1. What is the main purpose of Firebase Analytics in an Android app?
easy
A. To manage app permissions
B. To store user passwords securely
C. To create user interface layouts
D. To track user actions and events within the app

Solution

  1. Step 1: Understand Firebase Analytics role

    Firebase Analytics is designed to collect data about user interactions and events in the app.
  2. Step 2: Compare options with purpose

    Only To track user actions and events within the app describes tracking user actions, which matches Firebase Analytics' main use.
  3. Final Answer:

    To track user actions and events within the app -> Option D
  4. Quick Check:

    Firebase Analytics tracks user actions = A [OK]
Hint: Firebase Analytics tracks events and user behavior [OK]
Common Mistakes:
  • Confusing analytics with security or UI tasks
  • Thinking it manages app permissions
  • Assuming it stores sensitive data like passwords
2. Which is the correct Kotlin syntax to log a custom event named purchase with Firebase Analytics?
easy
A. firebaseAnalytics.logEvent("purchase", Bundle())
B. firebaseAnalytics.logEvent(purchase, null)
C. firebaseAnalytics.logEvent("purchase")
D. firebaseAnalytics.logEvent('purchase', null)

Solution

  1. Step 1: Recall logEvent method signature

    logEvent requires event name as String and a Bundle for parameters (can be empty).
  2. Step 2: Check options for correct syntax

    firebaseAnalytics.logEvent("purchase", Bundle()) uses a String event name and an empty Bundle(), which is valid Kotlin syntax.
  3. Final Answer:

    firebaseAnalytics.logEvent("purchase", Bundle()) -> Option A
  4. Quick Check:

    logEvent needs event name string and Bundle = D [OK]
Hint: Use event name as string and Bundle() for parameters [OK]
Common Mistakes:
  • Omitting quotes around event name
  • Passing null instead of Bundle()
  • Calling logEvent with only one argument
3. Given this Kotlin code snippet, what will be logged as the event name?
val bundle = Bundle()
bundle.putString("item", "book")
firebaseAnalytics.logEvent("select_content", bundle)
medium
A. "item"
B. "select_content"
C. "book"
D. No event will be logged

Solution

  1. Step 1: Identify event name argument

    The first argument to logEvent is the event name string "select_content".
  2. Step 2: Understand bundle role

    The bundle contains parameters, here "item" with value "book", but event name is separate.
  3. Final Answer:

    "select_content" -> Option B
  4. Quick Check:

    Event name is first argument = C [OK]
Hint: Event name is first string argument in logEvent [OK]
Common Mistakes:
  • Confusing parameter keys with event name
  • Thinking bundle keys become event names
  • Assuming no event logs without explicit call
4. What is wrong with this Kotlin code for logging an event?
val bundle = Bundle()
bundle.putString("level", "5")
firebaseAnalytics.logEvent(level, bundle)
medium
A. The variable 'level' is not defined as a String event name
B. Bundle cannot contain strings
C. logEvent requires only one argument
D. Bundle should be null instead of a Bundle object

Solution

  1. Step 1: Check event name argument

    logEvent expects a String event name, but 'level' is used as a variable, which is undefined here.
  2. Step 2: Validate bundle usage

    Bundle usage is correct; it can contain strings and is passed properly.
  3. Final Answer:

    The variable 'level' is not defined as a String event name -> Option A
  4. Quick Check:

    Event name must be a string literal or defined string = B [OK]
Hint: Event name must be a string, not an undefined variable [OK]
Common Mistakes:
  • Passing undefined variables as event names
  • Misunderstanding Bundle contents
  • Using wrong number of arguments in logEvent
5. You want to log a purchase event with item name and price using Firebase Analytics in Kotlin. Which code correctly logs this event with parameters?
hard
A. val bundle = Bundle() bundle.putString("item_name", "shoes") bundle.putDouble("price", "59.99") firebaseAnalytics.logEvent("purchase", bundle)
B. val bundle = Bundle() bundle.putString("item_name", "shoes") bundle.putFloat("price", "59.99f") firebaseAnalytics.logEvent("purchase", bundle)
C. val bundle = Bundle() bundle.putString("item_name", "shoes") bundle.putString("price", "59.99") firebaseAnalytics.logEvent("purchase", bundle)
D. val bundle = Bundle() bundle.putInt("item_name", 59) bundle.putDouble("price", 59.99) firebaseAnalytics.logEvent("purchase", bundle)

Solution

  1. Step 1: Check parameter types for Firebase Analytics

    Firebase Analytics Bundle supports putString for strings; price should be string or long, not double or float.
  2. Step 2: Analyze options for correct types

    val bundle = Bundle() bundle.putString("item_name", "shoes") bundle.putString("price", "59.99") firebaseAnalytics.logEvent("purchase", bundle) uses putString for both item_name and price, which is safe and accepted for Firebase Analytics parameters.
  3. Final Answer:

    val bundle = Bundle() bundle.putString("item_name", "shoes") bundle.putString("price", "59.99") firebaseAnalytics.logEvent("purchase", bundle) -> Option C
  4. Quick Check:

    Use putString for parameters to avoid type issues = A [OK]
Hint: Use putString for all parameters to ensure compatibility [OK]
Common Mistakes:
  • Using putDouble or putFloat which may cause errors
  • Putting numbers in wrong parameter keys
  • Using putInt for string values
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard