Example Custom Events
Example 1: Tracking Button Clicks
Log an event when a user clicks a specific button in your app.
For Android:
Bundle params = new Bundle();
params.putString("button_name", "subscribe");
mFirebaseAnalytics.logEvent("button_click", params);
For iOS:
analytics.logEvent("button_click", parameters: [
"button_name": "subscribe" as NSObject
])
For Web:
logEvent(analytics, 'button_click', {
button_name: 'subscribe'
});
Example 2: Tracking User Sign-Ups
Log an event when a user signs up for your app.
For Android:
Bundle params = new Bundle();
params.putString("method", "email");
mFirebaseAnalytics.logEvent("sign_up", params);
For iOS:
analytics.logEvent("sign_up", parameters: [
"method": "email" as NSObject
])
For Web:
logEvent(analytics, 'sign_up', {
method: 'email'
});
Example 3: Tracking In-App Purchases
Log an event when a user makes an in-app purchase.
For Android:
Bundle params = new Bundle();
params.putString("transaction_id", "T12345");
params.putDouble("value", 9.99);
params.putString("currency", "USD");
params.putParcelableArray("items", new Parcelable[] {
new Item("P123", "Product Name", "Category")
});
mFirebaseAnalytics.logEvent("purchase", params);
For iOS:
analytics.logEvent("purchase", parameters: [
"transaction_id": "T12345" as NSObject,
"value": 9.99 as NSObject,
"currency": "USD" as NSObject,
"items": [
["item_id": "P123", "item_name": "Product Name", "item_category": "Category"] as NSObject
]
])
For Web:
logEvent(analytics, 'purchase', {
transaction_id: 'T12345',
value: 9.99,
currency: 'USD',
items: [
{ item_id: 'P123', item_name: 'Product Name', item_category: 'Category' }
]
});
Example 4: Tracking Feature Engagement
Log an event when a user engages with a specific feature in your app.
For Android:
Bundle params = new Bundle();
params.putString("feature_name", "chat");
mFirebaseAnalytics.logEvent("feature_engagement", params);
For iOS:
analytics.logEvent("feature_engagement", parameters: [
"feature_name": "chat" as NSObject
])
For Web:
logEvent(analytics, 'feature_engagement', {
feature_name: 'chat'
});
Adding Firebase Custom Events for Analytics Conversion
Tracking user interactions and understanding their journey within our app is important for driving engagement and optimizing our apps performance. Firebase Analytics provides a robust framework for logging custom events, allowing us to measure key actions that contribute to conversions. In this article, we will explore how to add Firebase custom events for analytics conversion in detail.