Push Notifications Guide
Complete guide to sending push notifications.
Overview
Moontraze uses FCM (Firebase Cloud Messaging) for push notifications.
- Owner — Can send and receive
- User — Can only receive
100% free and unlimited.
Setup
Step 1: Enable in Dashboard
Project Settings → Push Notifications → Toggle ON
Step 2: Register FCM Token (Flutter)
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:moontraze_flutter/moontraze_flutter.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
final moon = MoonSDK(MoonConfig(projectId: 'xxx', apiKey: 'yyy'));
final token = await FirebaseMessaging.instance.getToken();
if (token != null) {
await moon.notifications.registerToken(token, {'platform': 'android'});
}
runApp(MyApp());
}Step 3: Register FCM Token (React Native)
import messaging from '@react-native-firebase/messaging';
await messaging().requestPermission();
const token = await messaging().getToken();
await moon.notifications.registerToken(token, { platform: 'android' });Step 4: Send Notification
Send to all users in project:
await moon.notifications.sendToProject('YOUR_PROJECT_ID', {
title: 'Hello',
body: 'World',
});Send to specific user:
await moon.notifications.sendToUser('USER_ID', {
title: 'Order Shipped',
body: 'Your order is on the way',
});Send to topic:
await moon.notifications.sendToTopic({
topic: 'premium_users',
title: 'Premium Feature',
body: 'Exclusive for premium users',
});Schedule for later:
await moon.notifications.schedule(
{
title: 'Reminder',
body: "Don't forget!",
},
new Date('2026-12-31T10:00:00Z'),
);Step 5: Get History
const history = await moon.notifications.getHistory(50);Step 6: Preferences
const prefs = await moon.notifications.getPreferences();
await moon.notifications.updatePreferences({
pushEnabled: true,
quietHoursEnabled: true,
quietHoursStart: '22:00',
quietHoursEnd: '08:00',
});Best Practices
- Request permission only when needed
- Handle token refresh
- Don't spam users
- Use meaningful titles and bodies
- Test on real devices (not emulator)