In this section

Resources / Developers / Embed

Push notifications on your own site

Host one service worker file so browsers ask for notification permission on your address instead of in a Hubbo window.

Hubbo can send a published post as a browser (web push) notification. A browser ties the notification permission to one origin. By default that origin is Hubbo’s: the bell in the widget opens a small window on app.hubbo.io, and nothing is installed on your site. If you want the browser to ask on your own address, and notifications to show your address, host one file. The product side is described in Push notifications.

Install the file

  1. In the admin app open Posts → Settings → Push, switch on Let visitors subscribe, choose On your own site and save.
  2. Download hubbo-push-sw.js from that page (it is also at https://app.hubbo.io/hubbo-push-sw.js).
  3. Serve it unchanged at the root of every origin that shows the widget.
https://your-site.com/hubbo-push-sw.js
RequirementWhy
Exactly this path, at the rootThe embed registers /hubbo-push-sw.js. A file in a subfolder or under another name is not found.
Same origin as the pageBrowsers do not register a service worker from another origin or from a CDN host.
https (or localhost while developing)Service workers and push need a secure context.
A JavaScript content type, for example text/javascriptBrowsers refuse a worker served as text/html or text/plain.
Status 200 without a redirectA redirected worker script is refused.

In frameworks, put the file in the folder that is served as-is: public/ in Next.js, Nuxt, Vite, Create React App and Astro, static/ in SvelteKit, and public/ or an assets entry in angular.json for Angular.

What the file does

  • It listens for push and shows a notification with the post title, the start of its text and your icon.
  • It listens for notificationclick and opens the post’s link, only when it is an http(s) address.
  • It has no fetch handler, caches nothing, stores nothing and loads no other script.

It does not touch your pages

The embed registers the worker with the scope /hubbo-push/, a path your site does not use. A worker controls only pages inside its scope, so it never sees a request of your site and it does not replace or conflict with a service worker you already run at /.

What the embed does

  1. Nothing on page load. First-load requests are the same with push on or off.
  2. When a visitor opens the widget panel for the first time on a page, the embed registers /hubbo-push-sw.js. Registering asks the visitor nothing.
  3. When the visitor clicks the bell, the embed calls Notification.requestPermission() and pushManager.subscribe() with Hubbo’s public VAPID key, then stores the subscription with client_savePushSubscription.
  4. A second click on the bell unsubscribes the browser and calls client_removePushSubscription.

If the registration fails (the file is missing, has the wrong content type, the page is not https, or your Content-Security-Policy blocks it), the bell opens the Hubbo window instead. The visitor sees no error. While the file is missing, each first opening of the panel requests /hubbo-push-sw.js once, so a 404 for that path in your logs means the file is not deployed on that origin.

Content Security Policy

If your site sends a Content-Security-Policy header, the worker needs worker-src 'self'. Without a worker-src directive browsers fall back to script-src (then default-src), which must include 'self'. The API calls go to https://api.hubbo.io, which the embed already needs in connect-src.

worker-src  'self';
script-src  'self' https://api.hubbo.io;
connect-src https://api.hubbo.io wss://api.hubbo.io;

The Hubbo window is opened with window.open from the visitor’s click and needs no CSP entry. A sandbox policy without allow-popups blocks it.

Check that it works

  1. Open https://your-site.com/hubbo-push-sw.js in a browser. You should see the script, not your 404 page.
  2. Open a page with the widget, open the panel and look at Application → Service workers in the browser’s developer tools. A worker with the scope /hubbo-push/ should be listed.
  3. Click the bell. The browser’s own permission prompt should appear on your page, with no extra window.
  4. Publish a test post with Push on and a targeting that matches you.

Client operations

The embed and the Hubbo window use these operations with the project key, like every client_* call. You do not need to call them yourself.

OperationDescription
client_getCurrentAccountappearance.push is { enabled, ownDomain, publicKey } when visitors can subscribe, otherwise null. publicKey is Hubbo’s public VAPID key.
client_savePushSubscriptionArguments subscription: JSON! (the result of PushSubscription.toJSON()) and language: String. Returns Boolean!. Only endpoints of known browser push services are accepted. Rate limited.
client_removePushSubscriptionArgument endpoint: String!. Returns Boolean!. Forgets the subscription with that endpoint.

Signed-in users

A subscription is linked to the user your site identified with window.hubbo.identify(), so Logged in and trait targeting work for push. With Identity Verification on, the link needs a valid userHash; otherwise the browser is stored as an anonymous subscriber. See Identify visitors.

Removing it

Switch back to In a Hubbo window and delete the file. Browsers that subscribed on your site keep their subscription until the visitor turns it off or clears site data; a subscription the browser dropped is removed from Hubbo at the next send.