0
0
Firebasecloud~10 mins

Custom events in Firebase - Step-by-Step Execution

Choose your learning style9 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.