Push Notification Script

The Rapidpace Notification SDK lets you send Web Push notifications to your visitors and track their delivery, clicks and dismissals automatically. The SDK handles permission requests, service worker registration, push subscription, and reports every notification interaction back to Rapidpace CRM.

Prerequisites

1. Host the Service Worker

Web Push requires a service worker. Download the RapidpaceSDKWorker.js file provided by your Account Manager and host it at the root of your domain so it is reachable at:

https://your-domain.com/RapidpaceSDKWorker.js

The file must be served from the root, otherwise the browser will refuse to register it for the whole site.

2. HTTPS

Web Push only works over HTTPS (or on localhost for development).

Installation

CDN Integration

Add the Rapidpace Notification SDK to your website using our CDN:

var urmNotificationSetting = {
 appId: "your-app-id",
 apiKey: "your-api-key",
 profileId: "user-123" // optional, see Profile ID strategies below
};


(function () {
 var w = window;
 var un = w && w.rapidpaceNotification;
 var d = document;
 if (typeof un === "object") {
   un.initNotification(urmNotificationSetting);
 } else {
   var l = function () {
     var s = d.createElement("script");
     s.type = "text/javascript";
     s.async = true;
     s.src =
       "https://cdn.urm.app/js/RapidpaceNotificationSDK.js?date=" +
       Date.now();
     var x = d.getElementsByTagName("script")[0];
     x.parentNode.insertBefore(s, x);
     s.onload = function () {
       window &&
         window.rapidpaceNotification &&
         window.rapidpaceNotification.initNotification(urmNotificationSetting);
     };
   };
   if (document.readyState === "complete") {
     l();
   } else if (w.attachEvent) {
     w.attachEvent("onload", l);
   } else {
     w.addEventListener("load", l, false);
   }
 }
})();

Quick Start:

  • The SDK is loaded asynchronously and initialized when the script is ready
  • It is exposed globally on window.rapidpaceNotification
  • On first call it will request the user's permission to show notifications. If the user accepts, the SDK subscribes the browser to Push and stores the subscription token on the user's profile.

Configuration Object

var urmNotificationSetting = {
 appId: "YOUR_APP_ID",
 apiKey: "YOUR_API_KEY",
 profileId: "USER_ID" // optional
};

Properties:

  • appId (string, required): Your Rapidpace App ID
  • apiKey (string, required): Your Rapidpace API key
  • profileId (string, optional): The user identifier. If omitted, an anonymous visitor ID will be generated and used until you call setProfileId from the Rapidpace Core / Chat SDK.

How It Works

  1. The SDK initializes the Rapidpace profile (creates one if it does not exist).
  2. It checks the browser's notification permission state.
  3. If permission is granted, it registers the service worker and subscribes the browser to Web Push.
  4. If permission is default, it triggers the browser permission prompt. On approval, it subscribes the browser.
  5. If permission is denied, no subscription is created (you must ask the user to re-enable it from the browser settings).
  6. The push subscription token is stored on the user profile under urm_web_push_notification_token so the Rapidpace platform can target the device.

Profile ID Management Strategies

1. Initialize with Known Profile ID

Use this approach when you already know the user's profile ID at initialization time (e.g., user is already logged in).

var urmNotificationSetting = {
 appId: "your-app-id",
 apiKey: "your-api-key",
 profileId: "user-123" // known profile ID
};

When to use:

  • User is already authenticated when the page loads
  • You have a persistent user identifier available immediately
  • Returning users with stored session data

2. Initialize Anonymously, Identify Later

If you don't know the user's ID at load time, initialize without it. The SDK will use an anonymous visitor ID and persist the push token against that ID.

When the user later authenticates, set the profile ID via the Rapidpace Chat / Core SDK and Rapidpace will automatically merge the anonymous push subscription with the authenticated profile:

// Initialize Notification SDK without profile ID (using the CDN code above)

// Later, when the user logs in
window.urmChat.setProfileId('user-123');

What happens:

  • Anonymous events and push tokens are merged into the authenticated profile
  • Future notifications target the authenticated profile
  • No user data is lost

API Reference

All methods are exposed on window.rapidpaceNotification after the SDK has loaded.

initNotification(settings)

Initializes the SDK, asks the user for permission and subscribes the browser to Web Push.

Parameters:

  • settings (object, required): Configuration object — see Configuration Object above.

Returns: Promise that resolves once initialization completes.

window.rapidpaceNotification.initNotification({
 appId: "your-app-id",
 apiKey: "your-api-key",
 profileId: "user-123"
});

enablePushNotification()

Marks the current profile as subscribed (sets the profile attribute urm_receives_notifications to true). Use this to re-opt-in a user that was previously soft-disabled.

window.rapidpaceNotification.enablePushNotification();

disablePushNotification()

Soft-disables push notifications for the current profile (sets urm_receives_notifications to false). The browser subscription is preserved, so the user can be re-enabled at any time without re-asking for permission.

When to use:

  • The user toggled "Notifications" off in your in-app preferences
  • You want a temporary opt-out without losing the subscription
window.rapidpaceNotification.disablePushNotification();

disablePushNotificationPermanent()

Permanently unsubscribes the current device from push notifications. The push subscription is removed from the browser, the service worker is unregistered, and the device's token is removed from the profile.

Returns: Promise that resolves with the unsubscribe result, or rejects with an error if the service worker / subscription cannot be found.

When to use:

  • The user explicitly wants to stop receiving notifications on this device
  • You are removing all Rapidpace integration from a specific device
window.rapidpaceNotification
 .disablePushNotificationPermanent()
 .then(function (result) {
   console.log("Unsubscribed:", result);
 })
 .catch(function (err) {
   console.error("Failed to unsubscribe:", err);
 });

disablePushNotificationPermanentAllDevice()

Removes all push tokens (web, iOS, Android) from the current profile, effectively stopping notifications across every device the user is signed into.

When to use:

  • Account-wide unsubscribe (e.g., "stop all notifications" preference)
  • Account deletion / GDPR-related data removal
window.rapidpaceNotification.disablePushNotificationPermanentAllDevice();

setPushNotificationToken(token)

Manually attaches a push subscription token to the current profile. The SDK calls this internally after a successful subscription, but you can also call it yourself if you manage the push subscription on your own (for example, in a custom hybrid app).

Parameters:

  • token (string, required): The push subscription serialized as JSON (i.e. the result of JSON.stringify(subscription.toJSON())).
window.rapidpaceNotification.setPushNotificationToken(
 JSON.stringify(subscription.toJSON())
);

Notification Event Tracking

Once the service worker is registered, Rapidpace automatically tracks the lifecycle of every push notification and forwards the events to the Rapidpace ingestion endpoint:

  • Received — fired when the device receives the push payload
  • Clicked — fired when the user clicks the notification (also opens the configured URL)
  • Dismissed — fired when the user closes the notification without clicking it

You can view these events in the Rapidpace dashboard under the user's profile timeline.

Troubleshooting

The browser never shows a permission prompt

  • Ensure the page is served over HTTPS
  • Make sure the user has not previously denied permission for your domain (the browser remembers this and will silently block future prompts)

"Service workers are not supported."

  • The visitor is using a browser that does not support Web Push (e.g. older iOS Safari versions)
  • The page is loaded inside a context that disables service workers (private browsing in some browsers)

The service worker fails to register

  • Verify RapidpaceSDKWorker.js is reachable at https://your-domain.com/RapidpaceSDKWorker.js
  • The file must be served with the Content-Type: application/javascript header
  • The service worker scope must be the site root, so the file must live at the root path
Close Modal