π₯Firebase - Push Notifications (Advanced)
Send push notifications to your users through Firebase Cloud Messaging.
What are Firebase Push Notifications?
Natively provides built-in support for Firebase Cloud Messaging (FCM) to handle push notification delivery for your app. Firebase manages device tokens and topic-based targeting through its own console, and you send notifications either directly from the Firebase console or via the Firebase Cloud Messaging API.
If you don't have a specific reason to manage Firebase yourself, consider OneSignal - Push Notifications instead, which offers a simpler dashboard-driven setup and a much easier API for sending notifications.
Prerequisites
This feature requires the Unlimited or Lifetime plan. See all plans
A Firebase account.
iOS:
An Apple Developer account.
Your iOS app is already published in the Natively Dashboard.
Android:
Your Android app is already published in the Natively Dashboard.
Pre-Firebase Configuration (iOS only)
To send push notifications to iOS devices, Firebase requires the Push Notifications App Capability enabled on your Bundle ID and an APNs authentication key from your Apple Developer account.
App Capabilities Configuration
App capabilities define what system-level features your app is allowed to use on iOS. Before Natively can include the Firebase Push Notifications feature in your build, the Push Notifications capability must be explicitly enabled in your Apple Developer account for your app's Bundle ID.
Open your Apple Developer account and navigate to Certificates, IDs & Profiles > Identifiers.
Select your app's Bundle ID.
Scroll down the Capabilities list and enable Push Notifications.
Click Save and confirm.
Set up APNs Authentication Key
Open your Apple Developer account and navigate to Certificates, IDs & Profiles > Keys.
Click + to register a new key.
Enter Key Name.
Select the Apple Push Notifications service (APNs) checkbox and click Configure.
In the Environment dropdown menu, select Sandbox & Production and click Save.
Click Continue, then Register.
Download the generated
.p8key.
You can only download this file once, so save it securely. If you lose it, you'll need to revoke the key and generate a new one.
Gather your credentials
Collect:
Key ID - located in the row of the key you just created. Make sure it matches the downloaded
.p8file.Team ID - located in your Apple Developer account under Membership details.
You'll need these for Firebase iOS Platform configuration.
Firebase Configuration
To send push notifications through Firebase, you'll need a Firebase project and Platforms configured for your app.
Create or open your Firebase Project
Go to the Firebase console.
If you donβt have a project yet, click Create a project and complete the setup.
If you already have a project, select it.
Confirm Firebase Cloud Messaging API v1 is enabled
While on the Project Overview page, select Settings > General from the left sidebar, then go to the Cloud Messaging tab.
Firebase Cloud Messaging API (V1) is enabled by default for most projects.
If it shows as disabled:
Click on the 3-dots menu.
Click Manage the API in Google Cloud Console.
Click Enable in the Google Cloud Console. Wait a few minutes for the change to reflect in Firebase.
Configure your platform
While on the Project Overview page, click the + Add app button under your project name.
Select Android.
In the Register app section:
Enter the Android package name (Bundle ID) of the app configured in your Natively Dashboard.
(Optional) Enter an App nickname; it will be used only in the Firebase Console to represent this app.
Click Register app.
In the Download and then add config file section, click Download google-services.json and save the
google-services.jsonfile in a secure location.Skip the SDK setup steps that follow, since Natively handles SDK integration for you, and click Continue to console at the end.
You can access the google-services.json file again at any time. While on the Project Overview page, select Settings > General from the left sidebar, scroll down to Your apps, select your Android app, and download the file under the SDK setup and configuration section.
Configure iOS app
While on the Project Overview page, click the + Add app button under your project name.
Select iOS(Apple).
In the Register app section:
Enter the Apple Bundle ID of the app configured in your Natively Dashboard.
(Optional) Enter an App nickname; it will be used only in the Firebase Console to represent this app.
(Optional) Enter an App Store ID (App Store App ID) of the app configured in your Natively Dashboard.
Click Register app.
In the Download and then add config file section, click Download google-services.json and save the
GoogleService-Info.plistfile in a secure location.Skip the SDK setup steps that follow, since Natively handles SDK integration for you, and click Continue to console at the end.
You can access the GoogleService-Info.plist file again at any time. While on the Project Overview page, select Settings > General from the left sidebar, scroll down to Your apps, select your iOS app, and download the file under the SDK setup and configuration section.
Upload your APNs Authentication Key
While on the Project Overview page, select Settings > General from the left sidebar, then go to the Cloud Messaging tab.
Scroll down to Apple app configuration and select your iOS app.
Under APNs Authentication Key in both development and production fields, provide the following and click Upload:
APNs Auth key -
.p8file you downloaded in the Set up APNs Authentication Key step above.Key ID and Team ID - gathered in the Gather your credentials step above.
Natively Dashboard Setup
Before proceeding, make sure you have completed the Firebase Configuration steps above.
Open your Natively app dashboard and navigate to Features > Notifications > Firebase.
Toggle the feature to Enabled.
Upload the Android Config file (
google-services.json) or/and the iOS Config file (GoogleService-Info.plist).Enter the Permission Description.
(Optional) Adjust the Automatically request push permission on app launch checkbox.
Click Save.
Rebuild your app(s).
The Permission Description is the text shown to users when the OS asks them to grant notification access. Explain clearly why your app needs this permission - for example: "We'll send you push notifications when your order ships."
The Automatically request push permission on app launch is enabled by default, triggering the system permission prompt immediately after the user launches the app. Disable it if you'd rather request permission later, at a more relevant moment in your app's flow.
You must rebuild your app for these changes to take effect.
Implementation
Choose your integration method below: Bubble.io Plugin (No-Code), JavaScript SDK (Code), or AI Agents (for AI-powered editors like Lovable, Base44, and Replit).
Initialization
Check Plugin
Before starting, verify if the Natively plugin is already installed in your Bubble project.
Open your Bubble editor and navigate to the Plugins tab in the left sidebar.
Check Installed Plugins: Look through your list of installed plugins for "Natively iOS & Android app builder".
If it IS installed: Check the version number. If an update is available (e.g., you see a button saying "Update"), click it to ensure you have the latest features and bug fixes.

If it is NOT installed: Click the + Add plugins button, search for "Natively", and click Install.

Check SDK
Before writing any logic, ensure the Natively SDK is correctly installed and up-to-date in your codebase.
Open your project's main HTML file (or header settings) and look for the Natively script tag inside the
<head>section.Install/Update: If missing or outdated, add the following code. You can specify the SDK version in the URL (e.g.,
@2.26.0).
To ensure you are using the most up-to-date version, check the Natively GitHub releases page for the latest version number.
Initialize the SDK
AI-powered editors like Lovable, Base44, and Replit use the JavaScript SDK to implement Natively features. Before implementing any feature, the Natively SDK must be initialized in your project.
Copy the line below and paste it into your AI agent to check and set up the Natively SDK in your project.
Setup logic
[Element] Natively - Push Notifications (Firebase)
This element must be set to Visible on page load to initialize correctly. It should be placed directly on the page root and not inside hidden containers, such as Popups, Floating Groups, Group Focus elements, or Repeating Groups. To hide the element from your UI, you may set its dimensions to 0x0 px.
On initialization, the element automatically attempts to retrieve the current notification permission status - no need to call it on the Page Is Loaded event.
Events:
Firebase FMC Token Updated - fires when the FCM token is updated.
Firebase APNS Token Updated - fires when the APNs token is updated.
Notification permissions authorized - fires when the user taps Allow on the permission alert.
Notification permissions denied - fires when the user taps Decline on the permission alert.
Notification permissions status updated - fires when permission status changes due to a user action.
Topic subscription status - fires when a subscribe/unsubscribe action's status updates.
States:
Permission Status - Yes/No.
Firebase FCM Token - the FCM token value.
Firebase APNS Token - the APNs token value.
Topic subscription status -
SUCCESSif the subscribe action succeeded.Topic unsubscribe status -
SUCCESSif the unsubscribe action succeeded.
Actions:
Request the user's push notification permission - displays the system permission popup using your configured Permission Description.
Get the user's Firebase APNS Token - reloads the user's Firebase APNS token.
Get the user's Firebase FCM Token - reloads the user's Firebase FCM token.
Get the user's push notification permission status
Subscribe to topic - subscribes to an FCM topic:
Topic ID - the FCM topic name.
Unsubscribe from topic - unsubscribes from an FCM topic:
Topic ID - the FCM topic name.
AI-powered editors like Lovable, Base44, and Replit use the JavaScript SDK to implement Natively features.
Copy the line below and paste it into your AI agent.
Replace the placeholder at the beginning with a description of what you want to build - for example: "Request push notification permission and save the FCM token to the user's profile on login".
How to use
Save both tokens on login - you'll need them to send notifications later
Store the FCM token (e.g. an fcm_token field on your user record) to send notifications on any platform. For iOS specifically, also store the APNs token (e.g. an apns_token field) if you send notifications directly via APNs rather than through FCM. Since tokens can change over time - after reinstalls or token refresh - retrieve and update them on every login rather than assuming a value saved once stays valid.
Check resp.status before treating permission as granted
firebase_request_permission only returns true when the user grants full authorization - any other state (denied, provisional, or not yet decided) returns false. Don't assume a non-true response means the request failed; it may simply mean the user hasn't fully authorized notifications.
Only call firebase_get_apns_token on iOS
This method always fails on Android with resp.message: "APNS token is only available on iOS". Check the platform first with Browser Info, and act upon the result.
Always provide a topic name
firebase_subscribe_to_topic and firebase_unsubscribe_from_topic fail with "Exception: Topic is required" if the topic is missing - validate the topic string before calling either method.
Use topics for broadcast-style targeting
Topics are best suited for sending the same notification to many users at once based on a shared interest or category (e.g. news_updates, weekly_digest) - subscribe users to relevant topics, then send a single notification to the topic instead of targeting each device individually.
Sending Notifications
Once a device's FCM token (and APNs token, for iOS) is saved, you can send notifications directly through the Firebase Console or the Cloud Messaging REST API.
Firebase Console - the simplest way to send a test or one-off notification to either an individual device or a topic. See Firebase Console Docs.
Cloud Messaging REST API - send notifications programmatically from your backend to either an individual device or a topic. See Cloud Messaging REST API Docs.
YOUR_API_KEY in the examples below is not a static API key - the FCM v1 API requires a short-lived OAuth2 access token, generated from your Firebase project's service account credentials. See Authorizing send requests for how to generate one.
The data.url field is what enables deep linking - when the user taps the notification, Natively opens this URL inside your app instead of just launching to the home screen.
To a topic's subscribers:
To a single user:
Troubleshooting
Notifications don't arrive at all
Go through this checklist:
Feature is enabled, and the config file for each platform your app supports is uploaded -
google-services.jsonfor Android,GoogleService-Info.plistfor iOS. If you support both platforms, make sure both files are uploaded, not just one.App rebuilt after configuration. Changes to this feature only take effect after a rebuild. If you configured or updated this after your last build, rebuild and test again.
Token actually saved and targeted correctly. Confirm the FCM token used in your send request matches a token retrieved from the device you're testing on - a stale or mistyped token will silently fail to deliver.
Permission granted on the device. Confirm
firebase_has_permissionreturnstrueon the test device - if notification permission was never granted, no notification will be delivered regardless of a correct setup.Testing on a real build, not Preview or a browser. This is a native feature and requires a full Natively build installed on a real device.
Notifications only appear while the app is open, not in the background or when closed
This is most commonly caused by:
Android missing Notifications permission. Confirm
firebase_has_permissionreturnstrue- if the runtime notification permission was never granted, foreground notifications may still work (since the app can display them directly), but system-level background notifications will be silently dropped.Manufacturer battery management. Some Android manufacturers (Xiaomi, Huawei, Samsung, and others) aggressively kill background processes or restrict notification delivery for apps not explicitly exempted from battery optimization. Check the device's battery/power management settings and allow the app to run unrestricted in the background.
Payload structure. If your payload only contains a
datablock with nonotificationblock, some Android OEMs won't display anything unless the app is in the foreground to handle it manually - see see Firebase Cloud Messaging message types for the distinction.
REST API call fails or returns an error
Confirm you're using a valid, current OAuth2 access token as the Bearer token - not a static Server Key, which is only valid for the deprecated legacy HTTP API. See the FCM error codes reference to interpret the specific error returned.
Notification doesn't trigger any app behavior when tapped, or doesn't deep link correctly
Confirm the data.url field is included in your payload with the correct URL. If your payload only includes a notification block with no data block, the OS displays the notification but your app has nothing to act on when it's tapped - see Firebase Cloud Messaging message types for the distinction.
Notifications sent from the Firebase Console arrive with a noticeable delay
This is expected behavior for messages sent as Campaigns through the Firebase Console UI - Firebase batches and schedules campaign delivery rather than sending immediately, which can introduce a delay of several minutes or more. For immediate, real-time delivery, send via the Cloud Messaging HTTP v1 API instead.
Last updated