Analytics
Analytics
Firebase Analytics provides free, unlimited event tracking and reporting, helping developers understand how users interact with their React Native applications.
Installing Firebase Analytics
bash
npm install @react-native-firebase/analytics
Logging a Screen View
javascript
import analytics from '@react-native-firebase/analytics';
await analytics().logScreenView({
screen_name: 'ProductDetails',
screen_class: 'ProductDetailsScreen',
});
Logging Custom Events
javascript
await analytics().logEvent('add_to_cart', {
item_id: product.id,
item_name: product.name,
price: product.price,
});
Setting User Properties
javascript
await analytics().setUserProperty('subscription_tier', 'premium');
Setting a User ID
javascript
await analytics().setUserId(user.id);
Tracking Purchases
javascript
await analytics().logPurchase({
currency: 'USD',
value: 49.99,
items: [{ item_id: 'sku123', item_name: 'Premium Plan' }],
});
Automatic Screen Tracking with React Navigation
javascript
{
const currentRoute = navigationRef.current?.getCurrentRoute();
await analytics().logScreenView({ screen_name: currentRoute?.name });
}}
>
Conclusion
Firebase Analytics provides valuable, free insight into user behavior within your React Native application, helping inform product decisions based on real usage data rather than assumptions.

