Skip to content

Complete React Native Firebase integration with Push Notifications & Analytics. Features modern UI, real-time testing, comprehensive event tracking, and production-ready code. Perfect starter template for Firebase-powered React Native apps.

Notifications You must be signed in to change notification settings

salmanazamdev/rn-firebase-complete

Repository files navigation

πŸ”₯ React Native Firebase Complete Integration

A comprehensive React Native application demonstrating Firebase Push Notifications and Firebase Analytics integration with a beautiful, production-ready UI.

✨ Features

πŸ“± Push Notifications

  • βœ… Foreground Notifications - Alert dialogs when app is active
  • βœ… Background Notifications - System notifications in notification bar
  • βœ… Notification Channels - Proper Android 8.0+ channel management
  • βœ… FCM Token Management - Easy token copying for testing
  • βœ… Local Notifications - Test notifications without server
  • βœ… Notification History - Track received notifications in-app

πŸ“Š Analytics Integration

  • βœ… Event Tracking - Comprehensive user interaction analytics
  • βœ… Screen Views - Automatic screen tracking
  • βœ… User Properties - User segmentation support
  • βœ… Custom Events - Business-specific event logging
  • βœ… Real-time Testing - DebugView integration for live testing
  • βœ… Error Tracking - Analytics error monitoring

🎨 UI/UX Features

  • βœ… Modern Material Design - Clean, professional interface
  • βœ… Status Indicators - Real-time feature status display
  • βœ… Interactive Testing - Built-in test buttons for all features
  • βœ… Comprehensive Guides - In-app testing instructions
  • βœ… Responsive Layout - Works on all Android screen sizes

πŸš€ Quick Start

Prerequisites

  • React Native development environment set up
  • Android Studio installed
  • Firebase project created
  • Physical Android device (recommended for push notifications)

Installation

  1. Clone the repository
git clone https://github.com/salmanazamdev/rn-firebase-complete
cd rn-firebase-complete
  1. Install dependencies
npm install
# or
yarn install
  1. Install required Firebase packages
npm install @react-native-firebase/app
npm install @react-native-firebase/messaging
npm install @react-native-firebase/analytics
npm install react-native-push-notification
  1. Firebase Setup

    • Create a Firebase project at Firebase Console
    • Add Android app to your project
    • Download google-services.json
    • Place it in android/app/ directory
    • Enable Cloud Messaging and Analytics in Firebase Console
  2. Android Configuration

Add to android/app/build.gradle:

dependencies {
    implementation 'com.google.firebase:firebase-messaging:23.1.0'
    implementation 'com.google.firebase:firebase-analytics:21.5.0'
}

apply plugin: 'com.google.gms.google-services'

Add to android/build.gradle:

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.4.0'
    }
}
  1. Run the application
npx react-native run-android

πŸ§ͺ Testing

Push Notifications Testing

  1. Get FCM Token

    • Launch the app
    • Tap "Copy Token to Console"
    • Copy the token from terminal
  2. Send Test Notification

    • Go to Firebase Console β†’ Cloud Messaging
    • Click "Send your first message"
    • Enter title and body
    • Click "Test on device"
    • Paste your FCM token
    • Send!
  3. Test Different States

    • Foreground: Keep app open β†’ Should show alert
    • Background: Press home button β†’ Should show in notification bar
    • Closed: Close app completely β†’ Should show in notification bar

Analytics Testing

  1. Enable Debug Mode
adb shell setprop debug.firebase.analytics.app com.pushnotificationdemo
  1. Real-time Testing

    • Go to Firebase Console β†’ Analytics β†’ DebugView
    • Tap "Test Analytics Event" in app
    • See events appear in real-time!
  2. View Reports

    • Firebase Console β†’ Analytics β†’ Events
    • Firebase Console β†’ Analytics β†’ Dashboard
    • Data appears within 24-48 hours for reports

πŸ“‹ Firebase Console Setup

1. Enable Cloud Messaging

  • Firebase Console β†’ Project Settings β†’ Cloud Messaging
  • Note your Server Key for API testing

2. Enable Analytics

  • Firebase Console β†’ Analytics β†’ Dashboard
  • Click "Enable Analytics" if not enabled
  • Link to Google Analytics account

3. Verify Configuration

  • Check that google-services.json package name matches your app
  • Ensure both services are enabled in your Firebase project

πŸ› οΈ Customization

Adding Custom Events

import analytics from '@react-native-firebase/analytics';

// Log custom event
await analytics().logEvent('custom_event_name', {
  parameter_1: 'value1',
  parameter_2: 123,
  timestamp: Date.now(),
});

Adding User Properties

// Set user properties
await analytics().setUserProperty('user_type', 'premium');
await analytics().setUserProperty('preferred_category', 'tech');

Custom Notification Channels

PushNotification.createChannel({
  channelId: "custom_channel",
  channelName: "Custom Notifications",
  importance: 5,
  vibrate: true,
});

πŸ“Š Analytics Events Tracked

The app automatically tracks:

  • app_open - App launches
  • screen_view - Screen transitions
  • notification_received - Push notifications received
  • notification_opened_app - App opened via notification
  • fcm_token_received - FCM token generation
  • test_local_notification_sent - Test notification sent
  • analytics_initialized - Analytics setup complete
  • notifications_cleared - Notification history cleared

πŸ› Troubleshooting

Common Issues

Notifications not appearing?

  • Check device notification permissions
  • Disable battery optimization for your app
  • Ensure google-services.json is in correct location
  • Verify notification channel setup

Analytics not working?

  • Check if Analytics is enabled in Firebase Console
  • Verify google-services.json configuration
  • Use DebugView for real-time testing
  • Events may take 24-48 hours to appear in reports

Build errors?

cd android && ./gradlew clean && cd .. && npx react-native run-android

Debug Commands

# Check app logs
adb logcat | grep -i "firebase"

# Enable analytics debug mode
adb shell setprop debug.firebase.analytics.app YOUR_PACKAGE_NAME

# Clear app data
adb shell pm clear YOUR_PACKAGE_NAME

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ™ Acknowledgments

πŸ“ž Support

If you have any questions or need help:

  1. Check the Issues page
  2. Create a new issue with detailed information
  3. LinkedIn

⭐ Star this repo if it helped you! It motivates me to create more awesome projects.

πŸ”„ Recent Updates

  • βœ… Added comprehensive Firebase Analytics integration
  • βœ… Enhanced UI with real-time status indicators
  • βœ… Added in-app testing tools for both features
  • βœ… Improved error handling and logging
  • βœ… Added user properties and custom event tracking
  • βœ… Added detailed testing guides and troubleshooting