Docs / Websites
Web SDKAvailable
Browser notifications with one script tag: subscription, friendly permission prompt, events and an offline queue.
Before you start
- In the dashboard, under Channels and credentials → Web, generate the VAPID keys.
- Authorize your site's domain (e.g. https://shop.com) and verify it with the file under /.well-known/ or a DNS TXT record. localhost is verified automatically.
- Copy the app's public key (vp_pub_…).
1. Publish the service worker
Browsers only deliver push to a service worker on the same domain. Download /sdk/vivapush-sw.js and serve it from your site's root, as https://your-site/vivapush-sw.js.
If the site already has a service worker (PWA, Workbox, Firebase), don't add another: import VivaPush's into yours and pass its path at initialization.
// in your service worker
importScripts('/vivapush-sw.js');2. Add the script
<script src="https://vivapush.com/sdk/vivapush.js"></script>
<script>
VivaPush.initialize("vp_pub_YOUR_KEY");
VivaPush.showSoftPrompt();
</script>The soft prompt explains first and opens the browser prompt only when the person clicks Allow: browsers penalize prompts without a user gesture, and Safari requires the click.
3. Users and attributes
VivaPush.login("customer-42"); // after sign-in on your site
VivaPush.setAttributes({ plan: "premium", points: 1240 });
VivaPush.removeAttributes(["plan"]);
VivaPush.setMarketingOptIn(false); // no marketing
VivaPush.logout();Everything can be called before permission: the SDK stores it and sends it with the first registration.
4. Clicks and notifications while the page is open
VivaPush.onNotificationOpened((n) => console.log(n.title, n.url, n.data));
VivaPush.onForegroundNotification((n) => showToast(n.title));
const opened = await VivaPush.initialNotification(); // the click that opened this tab
VivaPush.setUrlHandler((url) => router.push(new URL(url).pathname));Options
| Option | Default | For |
|---|---|---|
baseUrl | https://vivapush.com | Your VivaPush address |
serviceWorkerPath | /vivapush-sw.js | Path of your service worker |
autoPrompt | false | Shows the soft prompt on its own ({ type: 'slidedown' | 'bell', delayMs }) |
showInForeground | true | Shows notifications while the page is focused |
logLevel | error | none, error, info or debug |
Accepted, but nothing appeared
If the send shows the provider accepted it and nothing appeared on screen, the operating system is almost always holding the notification:
- macOS: System Settings → Notifications → (your browser, e.g. Google Chrome): turn on Allow notifications and pick the Banners or Alerts style.
- macOS: check that no Focus (Do Not Disturb) is on in Control Center.
- Windows: Settings → System → Notifications: turn notifications on for your browser and turn off Do not disturb.
- In the browser, check that the site may show notifications (icon next to the address).