P Push Notification Service

Quickstart

You'll have a working push subscription in about five minutes.

1. Create a site

In the dashboard, go to Sites → Add site and enter your domain (e.g. example.com). You'll get a Site ID and a VAPID public key. You only need the Site ID for the snippet.

2. Add the snippet

Paste this before the closing </body> tag on every page:

<script async
  src="//cdn.pushnotificationservice.com/sdk/v1.js"
  data-site="YOUR_SITE_ID"></script>

3. Add the service worker

Browsers require the service worker to be served from your domain. Create a file at the root of your site (https://example.com/pns-sw.js) containing a single line:

importScripts('//cdn.pushnotificationservice.com/sdk/v1/sw.js');

It must be reachable at the root so it can control your whole site. If you must host it elsewhere, set data-sw="/path/to/pns-sw.js" on the snippet.

4. Ask for permission

Prompting on page load leads to high denial rates, so by default the SDK waits. Call subscribe() from a click (a “Get notified” button is ideal):

<button onclick="PushSvc.subscribe()">Enable notifications</button>

Prefer to prompt automatically? Add data-prompt="auto" to the snippet and it will ask a couple of seconds after load.

5. Send your first notification

Back in the dashboard, open your site → Notifications → New notification, write a title and body, and send. Or use the API:

curl -X POST \
  //api.pushnotificationservice.com/v1/sites/YOUR_SITE_ID/notifications \
  -H "Authorization: Bearer pns_live_..." \
  -H "Content-Type: application/json" \
  -d '{"title":"Hello!","body":"Your first web push.","url":"https://example.com"}'

That's it. Head to the REST API reference for everything else.