This code sends a custom event named 'purchase' with details about the item and price to Firebase Analytics.
Process Table
Step
Action
Event Name
Event Parameters
Result
1
User triggers purchase
purchase
{item: 'sword', price: 10}
Event object created
2
Call logEvent
purchase
{item: 'sword', price: 10}
Event sent to Firebase
3
Firebase receives event
purchase
{item: 'sword', price: 10}
Event recorded in Analytics
4
Analytics dashboard updates
purchase
{item: 'sword', price: 10}
Event visible for analysis
5
No more events
-
-
Execution ends
💡 No more events to send; process completes
Status Tracker
Variable
Start
After Step 1
After Step 2
After Step 3
Final
eventName
undefined
purchase
purchase
purchase
purchase
eventParams
undefined
{item: 'sword', price: 10}
{item: 'sword', price: 10}
{item: 'sword', price: 10}
{item: 'sword', price: 10}
eventSent
false
false
true
true
true
eventRecorded
false
false
false
true
true
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.