Bird
Raised Fist0
Firebasecloud~10 mins

Custom events in Firebase - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Custom events
User triggers action
↓
Create custom event object
↓
Send event to Firebase Analytics
↓
Firebase records event
↓
Event data available in Analytics dashboard
This flow shows how a user action creates a custom event, which is sent to Firebase Analytics and recorded for later analysis.
Execution Sample
Firebase
firebase.analytics().logEvent('purchase', {item: 'sword', price: 10});
This code sends a custom event named 'purchase' with details about the item and price to Firebase Analytics.
Process Table
StepActionEvent NameEvent ParametersResult
1User triggers purchasepurchase{item: 'sword', price: 10}Event object created
2Call logEventpurchase{item: 'sword', price: 10}Event sent to Firebase
3Firebase receives eventpurchase{item: 'sword', price: 10}Event recorded in Analytics
4Analytics dashboard updatespurchase{item: 'sword', price: 10}Event visible for analysis
5No more events--Execution ends
💡 No more events to send; process completes
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
eventNameundefinedpurchasepurchasepurchasepurchase
eventParamsundefined{item: 'sword', price: 10}{item: 'sword', price: 10}{item: 'sword', price: 10}{item: 'sword', price: 10}
eventSentfalsefalsetruetruetrue
eventRecordedfalsefalsefalsetruetrue
Key Moments - 3 Insights
Why do we need to specify event parameters like item and price?
Event parameters provide extra details about the event, making the data more useful in Analytics. See execution_table step 1 and 3 where parameters are included.
What happens if we call logEvent with the same event name multiple times?
Each call sends a separate event instance to Firebase. Analytics records all occurrences separately for accurate tracking.
Does the event get recorded immediately after calling logEvent?
No, the event is sent asynchronously. Execution_table step 2 shows sending, step 3 shows recording, which may happen shortly after.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the eventName after Step 2?
Apurchase
Bundefined
ClogEvent
Dfirebase
💡 Hint
Check the eventName column in execution_table row for Step 2
At which step does Firebase record the event in Analytics?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the Result column in execution_table for when eventRecorded becomes true
If we add a new parameter 'currency: USD' to the event, how does variable_tracker change?
AeventName will change to 'currency'
BeventParams will include currency: USD after Step 1
CeventSent becomes false
DeventRecorded becomes false
💡 Hint
Check eventParams values in variable_tracker after Step 1
Concept Snapshot
Custom events in Firebase let you track specific user actions.
Use firebase.analytics().logEvent('eventName', {params}) to send events.
Events include a name and optional parameters with details.
Firebase records events asynchronously and shows them in Analytics.
Use descriptive names and parameters for better insights.
Full Transcript
Custom events in Firebase start when a user triggers an action. The app creates an event object with a name and parameters. Then it calls firebase.analytics().logEvent to send the event. Firebase receives and records the event asynchronously. Finally, the event appears in the Analytics dashboard for review. Parameters add useful details to events. Multiple calls with the same event name create separate records. Events are not recorded instantly but shortly after sending.

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