Skip to main content

🔔 Push notifications

Stay connected with your customers by utilizing push notifications to alert them of new chat messages, release notes, and news articles. This will deepen engagement and foster stronger relationships.

Gleap supports Firebase Cloud Messaging to send push notifications to users.

Setup Firebase Cloud Messaging

To make use of Gleap Push Notifications you must add the Firebase Cloud Messaging service to your app or website. Learn how to get started with FCM here.

Getting your Firebase Cloud Messaging Token

Open your project in Firebase and open the project settings.

Click on "Cloud Messaging" and, if it is not already enabled, activate the Firebase Cloud Messaging API (V1).

Gleap Firebase Setup

Proceed to the "Service Accounts" section and generate a new private key, which will automatically create a file named like serviceAccountKey.json.

Gleap Firebase Setup

Next, open the project settings in Gleap, select "Push Notifications", and upload the serviceAccountKey.json file. Finally, save your configuration.

Gleap Push Notifications Setup

Subscribe to the Gleap user topic

The last step to complete the push notification setup is to subscribe to the user topic, which Gleap will send the push notifications to. In order to do so, you will need to register the register & unregister push message topic callbacks.

// Find more information here:
// https://github.com/capacitor-community/fcm
import { FCM } from "@capacitor-community/fcm";
import { PushNotifications } from "@capacitor/push-notifications";

// external required step
// register for push
await PushNotifications.requestPermissions();
await PushNotifications.register();

// Subscribe & unsubscribe to the Gleap topics
Gleap.registerListener("registerPushMessageGroup", (topic) => {});

Gleap.setEventCallback((message, err) => {
const { name, data } = message;

if (name === "register-pushmessage-group") {
FCM.subscribeTo({ topic: data })
.then((r) => alert(`subscribed to topic`))
.catch((err) => console.log(err));
}
if (name === "unregister-pushmessage-group") {
FCM.unsubscribeFrom({ topic: data })
.then((r) => alert(`unsubscribed to topic`))
.catch((err) => console.log(err));
}
});

That's it - build and run your app 🚀