An open API service indexing awesome lists of open source software.

https://github.com/salmanazamdev/rn-firebase-complete

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.
https://github.com/salmanazamdev/rn-firebase-complete

analytics android-development fcm fcm-messaging fcm-notifications fcm-push-notification firebase firebase-analytics firebase-auth google-analytics mobile-development notification notifications push-notification-api push-notifications react-native react-native-cli typescript

Last synced: 4 months ago
JSON representation

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.

Awesome Lists containing this project

README

          

# ๐Ÿ”ฅ 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**
```bash
git clone https://github.com/salmanazamdev/rn-firebase-complete
cd rn-firebase-complete
```

2. **Install dependencies**
```bash
npm install
# or
yarn install
```

3. **Install required Firebase packages**
```bash
npm install @react-native-firebase/app
npm install @react-native-firebase/messaging
npm install @react-native-firebase/analytics
npm install react-native-push-notification
```

4. **Firebase Setup**
- Create a Firebase project at [Firebase Console](https://console.firebase.google.com/)
- Add Android app to your project
- Download `google-services.json`
- Place it in `android/app/` directory
- Enable **Cloud Messaging** and **Analytics** in Firebase Console

5. **Android Configuration**

Add to `android/app/build.gradle`:
```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`:
```gradle
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.4.0'
}
}
```

6. **Run the application**
```bash
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](https://console.firebase.google.com/) โ†’ 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**
```bash
adb shell setprop debug.firebase.analytics.app com.pushnotificationdemo
```

2. **Real-time Testing**
- Go to Firebase Console โ†’ Analytics โ†’ DebugView
- Tap "Test Analytics Event" in app
- See events appear in real-time!

3. **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
```typescript
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
```typescript
// Set user properties
await analytics().setUserProperty('user_type', 'premium');
await analytics().setUserProperty('preferred_category', 'tech');
```

### Custom Notification Channels
```typescript
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?**
```bash
cd android && ./gradlew clean && cd .. && npx react-native run-android
```

### Debug Commands
```bash
# 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

- [React Native Firebase](https://rnfirebase.io/) for excellent Firebase integration
- [Firebase](https://firebase.google.com/) for powerful backend services
- [React Native Push Notification](https://github.com/zo0r/react-native-push-notification) for local notifications

## ๐Ÿ“ž Support

If you have any questions or need help:

1. Check the [Issues](https://github.com/salmanazamdev/rn-firebase-complete/issues) page
2. Create a new issue with detailed information
3. [LinkedIn](https://www.linkedin.com/in/salmanazamdev?)

---

โญ **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