Push notifications are the feature customers notice most in a tracking app. "Vehicle left the depot", "Overspeed: 92 km/h", "SOS from Driver 4": they want those on their phone instantly, not in an email they'll read tomorrow.
Traccar can send push notifications through Firebase Cloud Messaging (FCM). The official Traccar apps use a push service run by the Traccar project. If you have your own branded app, you need your own Firebase project so notifications arrive in your app under your name.
This post explains how the pieces connect and walks through the setup. Config key names can change between Traccar versions, so check the configuration documentation for your exact version as you go.
How it works
- Your app registers with Firebase and gets an FCM token, a unique address for that app install.
- The app saves the token on the user's Traccar account.
- When an event happens (geofence, overspeed, alarm), Traccar sends the notification to Firebase, addressed to the user's tokens.
- Firebase delivers it to the phone.
Traccar handles step 3. Your app handles steps 1 and 2.
1. Create the Firebase project
- Go to the Firebase console and create a project (one per brand or app).
- Add an Android app with your app's package name, and an iOS app with your bundle ID.
- For iOS, upload your APNs authentication key in Project settings → Cloud Messaging. iOS push won't work without it.
- Download
google-services.json(Android) andGoogleService-Info.plist(iOS) for your Flutter project.
2. Give Traccar permission to send
Traccar needs a service account key to send messages through your Firebase project:
- In the Firebase console, go to Project settings → Service accounts.
- Click Generate new private key. This downloads a JSON file.
- Treat that file like a password. It allows sending notifications as your app.
In /opt/traccar/conf/traccar.xml, enable the Firebase notificator and give it the service account. Recent Traccar 5.x versions use settings along these lines:
<entry key='notificator.types'>web,mail,firebase</entry>
<entry key='notificator.firebase.serviceAccount'>{ ...contents of the JSON file... }</entry>
Keep any notificators you already use (like web and mail) in the list. Restart Traccar afterwards:
sudo systemctl restart traccar
If the server log shows errors about the Firebase notificator at startup, compare your keys against the documentation for your version. Older versions used a different, key-based setting.
3. Register the device token from Flutter
Add Firebase to your Flutter app with the firebase_core and firebase_messaging packages, and run flutterfire configure to wire up the platform files.
After the user logs in to Traccar, get the FCM token and save it on their Traccar user. Traccar reads tokens from a user attribute (commonly notificationTokens, a comma-separated list, so one user can have several phones):
import 'dart:convert';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:http/http.dart' as http;
Future<void> registerPushToken({
required String serverUrl, // https://track.example.com
required Map<String, String> authHeaders, // session cookie or Authorization header
}) async {
final messaging = FirebaseMessaging.instance;
await messaging.requestPermission();
final token = await messaging.getToken();
if (token == null) return;
// Load the current user.
final res = await http.get(Uri.parse('$serverUrl/api/session'), headers: authHeaders);
final user = jsonDecode(res.body) as Map<String, dynamic>;
// Add this phone's token to the list, without dropping other phones.
final attributes = Map<String, dynamic>.from(user['attributes'] ?? {});
final tokens = (attributes['notificationTokens'] as String? ?? '')
.split(',')
.where((t) => t.isNotEmpty)
.toSet()
..add(token);
attributes['notificationTokens'] = tokens.join(',');
await http.put(
Uri.parse('$serverUrl/api/users/${user['id']}'),
headers: {...authHeaders, 'Content-Type': 'application/json'},
body: jsonEncode({...user, 'attributes': attributes}),
);
}
Also handle token changes. Firebase can rotate tokens, so listen to FirebaseMessaging.instance.onTokenRefresh and save the new one the same way. On logout, remove this phone's token from the list so the next user of the phone doesn't get someone else's alerts.
4. Turn on push for events
In the Traccar web interface, go to Settings → Notifications:
- Add or edit a notification, for example Geofence exit or Alarm.
- Tick the Firebase (push) channel.
- Link it to the right devices or groups.
Users only receive notifications for devices they have access to.
5. Test it
- Trigger an easy event: create a geofence around your desk and walk out of it with a phone running a tracker app, or send a test SOS.
- Check the phone in the background and with the app closed, since that's how users will receive it.
- If nothing arrives, check the Traccar log for Firebase errors, and confirm the token is saved on the user (open the user in the web interface and look at attributes).
Common problems
| Problem | Likely cause |
|---|---|
| Android works, iOS doesn't | APNs key not uploaded to Firebase, or push capability missing in Xcode |
| Nothing arrives at all | Firebase notificator not enabled, or invalid service account config. Check the Traccar log at startup. |
| Only one phone gets alerts | The app overwrites the token list instead of adding to it |
| Old users still get alerts | Tokens not removed on logout |
| Alerts for some events only | The notification isn't linked to those devices, or the Firebase channel isn't ticked |
Summary
- Create a Firebase project with your Android and iOS apps.
- Give Traccar a service account key and enable the Firebase notificator.
- Save each phone's FCM token on the user's Traccar account, and keep it updated.
- Tick the Firebase channel on the notifications you want pushed.
This is a core part of my white-label GPS tracking app service: your own branded app, connected to your Traccar server, with push notifications working on Android and iOS.
