Proem Sports Documentation
  • FUNDAMENTALS
    • Getting Started
      • Platform Overview
      • Fans
      • Account setting
        • Settings
        • Do Not Disturb (DND)
        • Frequency capping
      • Integrations
        • Web tracker
        • App Tracker
        • Setting up email service provider
          • Setting Up SendGrid as the Email Service Provider on Organon
          • Setting Up Mailjet as the Email Service Provider on Organon
        • Web push soft ask integration
        • Push notification integration
          • Setting Up Android Push Notifications
          • Setting Up iOS Push Notifications
          • Setting Up Web Push Notifications
      • File upload
        • How to upload files in Organon
      • Analytics
      • Social Media & Benchmarking
      • Segments
      • Marketing
        • Email
        • WhatsApp
        • Push Notifications
        • SMS
      • Forms
  • Segment creation
    • Segment operators
      • Working with groups
    • Finalising the segment
    • Saving the segment
    • Managing a segment
    • Segment overview
    • Syncing with Meta Custom audiences
  • Steps to Using Email
    • Email campaign set up
    • Desiging Email campaigns
    • Audience and Scheduling
    • Review and Publish
  • WhatsApp campaign set-up
    • Creating a WhatsApp campaign
    • Setting Up the Campaign Content
    • Audience and Scheduling
    • Review and Publish
    • Campaign reports
  • SMS campaign set-up
    • Creating a SMS campaign
    • Audience and Scheduling
    • Review and Publish
    • Campaign Reports
  • Push notification campaign set-up
  • Push notification campaign process
  • Campaign reports
    • Email Campaign Report
    • Push Notification Campaign Report
  • Forms
    • Form set-up
    • Form design
    • Form save and publishing
    • Form reports
Powered by GitBook
On this page
  • Setting Up Web Push Notifications with Firebase Cloud Messaging (FCM)
  • Overview
  • Prerequisites
  • Step 1: Generate VAPID Keys
  • Step 2: Configure Firebase in Your Web Application
  • Step 3: Implement the Service Worker
  • Step 4: Request User Permission
  • Step 5: Configure Web Push Notifications in Organon
  • Step 6: Test Web Push Notifications
  • Step 7: Deploy and Monitor Notifications
  • Troubleshooting
  1. FUNDAMENTALS
  2. Getting Started
  3. Integrations
  4. Push notification integration

Setting Up Web Push Notifications

PreviousSetting Up iOS Push NotificationsNextFile upload

Last updated 3 months ago

Setting Up Web Push Notifications with Firebase Cloud Messaging (FCM)

Overview

This guide provides step-by-step instructions to configure Web Push Notifications using Firebase Cloud Messaging (FCM) for Organon. By following these steps, users can enable push notifications in their web applications and integrate FCM for seamless message delivery.


Prerequisites

Before proceeding, ensure you have:

  • A web application with HTTPS enabled (FCM requires HTTPS for push notifications).

  • Access to the Firebase Cloud Messaging credentials.


Step 1: Generate VAPID Keys

  1. Go to Project Settings > Cloud Messaging.

  2. Scroll to the Web configuration section.

  3. Click Generate Key Pair under the VAPID Key section.

  4. Copy the generated VAPID Public Key and VAPID Private Key.


Step 2: Configure Firebase in Your Web Application

  1. Add Firebase SDK to your project.

script src="https://www.gstatic.com/firebasejs/10.3.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.3.0/firebase-messaging.js"></script>
  1. Initialize Firebase with your configuration:

const firebaseConfig = {
    apiKey: "YOUR_API_KEY",
    authDomain: "YOUR_AUTH_DOMAIN",
    projectId: "YOUR_PROJECT_ID",
    storageBucket: "YOUR_STORAGE_BUCKET",
    messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
    appId: "YOUR_APP_ID"
};
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();

Step 3: Implement the Service Worker

  1. Create a firebase-messaging-sw.js file in the root directory of your project.

importScripts('https://www.gstatic.com/firebasejs/10.3.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/10.3.0/firebase-messaging.js');


firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();


messaging.onBackgroundMessage((payload) => {
    console.log('Received background message ', payload);
    self.registration.showNotification(payload.notification.title, {
        body: payload.notification.body,
        icon: payload.notification.icon
    });
});
  1. Register the service worker in your index.js file.

if ('serviceWorker' in navigator) {
    navigator.serviceWorker.register('/firebase-messaging-sw.js')
        .then((registration) => {
            console.log('Service Worker registered with scope:', registration.scope);
        })
        .catch((err) => {
            console.log('Service Worker registration failed:', err);
        });
}

Step 4: Request User Permission

  1. Add the following code in your main JavaScript file.

function requestNotificationPermission() {
    Notification.requestPermission().then((permission) => {
        if (permission === 'granted') {
            console.log('Notification permission granted.');
            return messaging.getToken();
        }
    }).then((token) => {
        console.log('FCM Token:', token);
    }).catch((error) => {
        console.error('Error getting permission:', error);
    });
}
  1. Call requestNotificationPermission() when users enable notifications.


Step 5: Configure Web Push Notifications in Organon

To send notifications from Organon, users must upload their Firebase Web Push credentials.

  1. Open Organon and navigate to Push Notification Settings.

  2. Select the Web tab.

  3. Enter the VAPID Private Key.

  4. Upload the firebase-messaging-sw.js file.

  5. Click Enable Web Push Configuration.

  6. Save the configuration.


Step 6: Test Web Push Notifications

Obtain Firebase Cloud Messaging Token

  1. Run your web app and call requestNotificationPermission().

  2. Copy the generated FCM token.

Send a Test Notification from Firebase Console

  1. Go to Firebase Console > Cloud Messaging.

  2. Click Send your first message.

  3. Enter a notification title and message.

  4. Select Send to a test device.

  5. Paste the copied FCM token.

  6. Click Send Message and check if the notification appears.


Step 7: Deploy and Monitor Notifications

Once testing is successful:

  • Use Organon’s campaign feature to send push notifications.

  • Monitor delivery rates and engagement using Organon’s analytics dashboard.

  • Optimize message content for better user interaction.


Troubleshooting

  • Ensure the Firebase configuration matches your project settings.

  • Verify that your service worker is correctly registered.

  • Check Organon’s notification logs for errors.

  • Ensure the user has granted permission for notifications.

Following these steps will enable web push notifications via Firebase Cloud Messaging and allow sending notifications directly from Organon.

A Firebase project set up in the.

Open the and select your project.

Firebase Console
Firebase Console