Course content
How to configure Firebase (FCM) in Traccar for Push Notifications
Step-by-step guide to configure Firebase Cloud Messaging (FCM) on your Traccar server and enable push notifications for your Android and iOS mobile apps.
Emmanuel Díaz Leal Hernández
Push notifications are essential for any modern tracking application. Traccar uses Firebase Cloud Messaging (FCM) to send these alerts to mobile devices efficiently and for free.
Prerequisites
- Have an account at Firebase Console.
- Have a Firebase project configured.
- If using a custom App, have the
google-services.json(Android) orGoogleService-Info.plist(iOS) file integrated into your source code.
Traccar Server Configuration
For the Traccar server to be able to send alerts to Firebase, we must configure the "Server Key" in the traccar.xml file.
1. Get the Firebase Key
- Enter your project in the Firebase Console.
- Click on the gear icon (Project Settings).
- Go to the Cloud Messaging tab.
- Copy the Server Key (if using the legacy API) or set up a Service Account for the v1 API (recommended).
2. Edit traccar.xml
Add the following entries to your configuration file:
<!-- Enable firebase notification type -->
<entry key='notificator.types'>web,mail,firebase</entry>
<!-- Firebase Server Key -->
<entry key='notificator.firebase.key'>YOUR_SERVER_KEY_HERE</entry>
Note: If you are using the new Firebase API, the process requires a service account JSON file, but most Traccar installations still use the classic Server Key.
How notifications reach the user
For a user to receive the push notification, two conditions must be met:
- Device Token: The mobile application must register the phone's "FCM Token" in the user attribute within Traccar. This happens automatically when the user logs in to the official app or a well-configured one.
- Attributes: The attribute in the database is generally saved as
fcmToken.
Testing the Setup
You can verify if the configuration is correct from the Traccar panel:
- Go to Settings -> Notifications.
- Select a notification and click the "Test" icon (the bell).
- If the server is correctly configured and the user has a valid token, the phone should receive the alert instantly.
Common Troubleshooting
- Notification not arriving: Verify that the phone has notification permissions enabled for the App and is not in an aggressive "Battery Saver" mode.
- Log Errors: Check the
tracker-server.logfile. If you see "401 Unauthorized" errors, it means yournotificator.firebase.keyis incorrect or has expired. - Token not registered: If the
fcmTokenattribute does not appear in the user, the mobile application is not communicating correctly with Firebase.
Properly configuring Firebase ensures your users never miss an important alert, improving security and trust in your tracking service.