Bird
Raised Fist0
Firebasecloud~10 mins

Custom events in Firebase - Interactive Code Practice

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

Complete the code to log a custom event named "purchase" using Firebase Analytics.

Firebase
firebase.analytics().logEvent([1]);
Drag options to blanks, or click blank then click option'
A"purchase"
B"login"
C"error"
D"click"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the event name
Using a predefined event name instead of the custom one
2fill in blank
medium

Complete the code to log a custom event "level_up" with a parameter "level" set to 5.

Firebase
firebase.analytics().logEvent("level_up", [1]);
Drag options to blanks, or click blank then click option'
A["level", 5]
B"level=5"
Clevel = 5
D{level: 5}
Attempts:
3 left
💡 Hint
Common Mistakes
Using an array instead of an object
Passing a string instead of an object
Using assignment syntax instead of an object
3fill in blank
hard

Fix the error in the code to correctly log a custom event "share" with parameter "method" set to "email".

Firebase
firebase.analytics().logEvent("share", [1]);
Drag options to blanks, or click blank then click option'
A"method: email"
B{method: "email"}
C[method: "email"]
D{method = "email"}
Attempts:
3 left
💡 Hint
Common Mistakes
Using equals (=) inside object
Using square brackets instead of curly braces
Passing parameters as a string
4fill in blank
hard

Fill both blanks to log a custom event "tutorial_complete" with parameters "step" set to 3 and "success" set to true.

Firebase
firebase.analytics().logEvent([1], [2]);
Drag options to blanks, or click blank then click option'
A"tutorial_complete"
B{step: 3, success: true}
C"tutorial_start"
D{step: 1, success: false}
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping event name and parameters
Using wrong event name
Passing parameters as a string
5fill in blank
hard

Fill both blanks to log a custom event "purchase" with parameters "item" set to "sword", "price" set to 10, and "currency" set to "USD".

Firebase
firebase.analytics().logEvent([1], [2]);
Drag options to blanks, or click blank then click option'
A"purchase"
B{item: "sword", price: 10, currency: "USD"}
C{item: "shield", price: 15, currency: "EUR"}
D"sale"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong event name
Incorrect parameter keys or values
Passing parameters as a string

Practice

(1/5)
1. What is the main purpose of custom events in Firebase Analytics?
easy
A. To replace default events with simpler ones
B. To automatically collect user location data
C. To track specific user actions not covered by default events
D. To send notifications to users

Solution

  1. Step 1: Understand default vs custom events

    Default events cover common actions, but some user actions need custom tracking.
  2. Step 2: Identify the role of custom events

    Custom events let you track specific actions unique to your app that default events don't cover.
  3. Final Answer:

    To track specific user actions not covered by default events -> Option C
  4. Quick Check:

    Custom events = track unique user actions [OK]
Hint: Custom events track unique actions default events miss [OK]
Common Mistakes:
  • Thinking custom events replace default events
  • Assuming custom events send notifications
  • Believing custom events collect location automatically
2. Which Firebase function is used to log a custom event with parameters?
easy
A. firebase.analytics().logEvent(eventName, params)
B. firebase.analytics().trackEvent(eventName, params)
C. firebase.analytics().sendEvent(eventName, params)
D. firebase.analytics().createEvent(eventName, params)

Solution

  1. Step 1: Recall Firebase Analytics API for events

    The correct method to log events is logEvent.
  2. Step 2: Confirm method signature

    logEvent takes the event name and optional parameters as arguments.
  3. Final Answer:

    firebase.analytics().logEvent(eventName, params) -> Option A
  4. Quick Check:

    logEvent = log custom events [OK]
Hint: Use logEvent to send custom events with parameters [OK]
Common Mistakes:
  • Using trackEvent instead of logEvent
  • Using sendEvent or createEvent which don't exist
  • Confusing parameter order or names
3. What will happen if you run this code snippet?
firebase.analytics().logEvent('purchase', {item: 'book', price: 15});
medium
A. Throws a syntax error due to incorrect parameter format
B. Logs a custom event named 'purchase' with item and price parameters
C. Logs a default event ignoring parameters
D. Sends an error because 'purchase' is a reserved event name

Solution

  1. Step 1: Analyze the logEvent call

    The code calls logEvent with event name 'purchase' and parameters object.
  2. Step 2: Check if 'purchase' is valid and parameters are correct

    'purchase' is a valid event name and parameters are passed as an object correctly.
  3. Final Answer:

    Logs a custom event named 'purchase' with item and price parameters -> Option B
  4. Quick Check:

    logEvent('purchase', params) = logs event with params [OK]
Hint: logEvent with name and object logs event with parameters [OK]
Common Mistakes:
  • Thinking 'purchase' is reserved and causes error
  • Assuming parameters must be strings only
  • Confusing syntax causing error
4. Identify the error in this Firebase custom event logging code:
firebase.analytics().logEvent('level_up', 'level', 5);
medium
A. Incorrect parameter format; parameters must be in an object
B. Event name must be uppercase
C. logEvent requires only one argument
D. The event name 'level_up' is invalid

Solution

  1. Step 1: Review logEvent parameter requirements

    logEvent expects the second argument as an object containing key-value pairs.
  2. Step 2: Identify the mistake in argument passing

    The code passes parameters as separate arguments instead of a single object.
  3. Final Answer:

    Incorrect parameter format; parameters must be in an object -> Option A
  4. Quick Check:

    Parameters must be an object, not separate arguments [OK]
Hint: Pass parameters as one object, not separate arguments [OK]
Common Mistakes:
  • Passing parameters as multiple arguments
  • Assuming event name case matters
  • Thinking logEvent takes only one argument
5. You want to track when users complete a tutorial step with step number and success status. Which is the best way to log this custom event in Firebase?
hard
A. firebase.analytics().logEvent('tutorial_complete', {step: stepNumber, success: isSuccess});
B. firebase.analytics().logEvent('tutorial_complete', stepNumber, isSuccess);
C. firebase.analytics().logEvent('tutorialComplete', {stepNumber, isSuccess});
D. firebase.analytics().logEvent('tutorial_complete', {stepNumber: stepNumber, success: isSuccess});

Solution

  1. Step 1: Check event name format

    Firebase recommends lowercase with underscores for event names, so 'tutorial_complete' is correct.
  2. Step 2: Verify parameters object keys and values

    Parameters should be an object with clear keys. firebase.analytics().logEvent('tutorial_complete', {stepNumber: stepNumber, success: isSuccess}); uses keys 'stepNumber' and 'success' with values from variables.
  3. Step 3: Compare options for best practice

    firebase.analytics().logEvent('tutorial_complete', {step: stepNumber, success: isSuccess}); uses 'step' key which is less descriptive than 'stepNumber'. firebase.analytics().logEvent('tutorialComplete', {stepNumber, isSuccess}); uses camelCase event name which is less recommended. firebase.analytics().logEvent('tutorial_complete', stepNumber, isSuccess); passes parameters incorrectly.
  4. Final Answer:

    firebase.analytics().logEvent('tutorial_complete', {stepNumber: stepNumber, success: isSuccess}); -> Option D
  5. Quick Check:

    Use descriptive keys and correct event name format [OK]
Hint: Use descriptive keys and underscore event names [OK]
Common Mistakes:
  • Passing parameters as separate arguments
  • Using camelCase event names instead of underscores
  • Using unclear parameter keys
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