Messaging (Web Push)

Send Web Push notifications to your users' browsers (Chrome, Edge, Firefox, Android Chrome, iOS 16.4+ PWA) — even when your site is closed. Works like Firebase Cloud Messaging for the web, powered by the standard Push API + VAPID. No Google account needed.

1. Enable

Console → Messaging → Setup & keys → Generate VAPID keys.

2. Service worker

Download clickbase-sw.js and put it at the root of your site (https://yourapp.com/clickbase-sw.js). Your site must be HTTPS (localhost is OK for testing).

3. Subscribe users

const app = ClickBase.init({ projectId: "my-shop", apiKey: "cb_pk_…" });

// call from a click handler (browsers require a user gesture for the permission prompt)
enableBtn.onclick = async () => {
  try {
    const r = await app.messaging.subscribe({ topics: ["offers", "orders"] });
    console.log("subscribed:", r.endpoint, r.topics);
  } catch (e) { alert(e.code + ": " + e.message); }   // push/denied, push/unsupported, push/not-configured
};

await app.messaging.isSubscribed();        // true / false
await app.messaging.setTopics(["news"], ["offers"]);   // add, remove
await app.messaging.unsubscribe();
app.messaging.onMessage(p => showToast(p.title));      // fired when a push arrives while the page is open

If the user is signed in, the subscription is linked to their uid, so you can target them individually. Anonymous subscriptions are allowed too (topics / all).

4. Send

Sending requires the secret key (server) or the console. Message fields: title (required), body, url (opened on click), icon, image, badge, tag, data, actions, requireInteraction, ttl. Audience: uid, uids[], topic, topics[], or none = everyone.

# REST
curl -X POST https://clickbase.thepakclicktes.com/v1/my-shop/push/send -H "X-API-Key: cb_sk_…" -H "Content-Type: application/json" \
  -d '{"title":"Order shipped 📦","body":"Your order #1042 is on the way","url":"/orders/1042","uid":"USER_UID"}'

// PHP SDK
$cb->push->toUser($uid, "Order shipped 📦", "Your order #1042 is on the way", "/orders/1042");
$cb->push->toTopic("offers", "Flash sale", "50% off for 2 hours");
$cb->push->toAll("Maintenance", "Tonight 2–3 AM PKT");

// Node (secret key)
const admin = ClickBase.init({ projectId: "my-shop", secretKey: "cb_sk_…" });
await admin.messaging.send({ title: "Hi", body: "…", topics: ["news"] });

Endpoints

Method & pathAuthPurpose
GET /push/vapidAPI key{publicKey, enabled}
POST /push/subscribeAPI key (+ Bearer to link uid){subscription, topics[]}
POST /push/unsubscribeAPI key{endpoint}
PATCH /push/topicsAPI key{endpoint, add[], remove[]}
GET /push/me?endpoint=API key{subscribed, topics}
POST /push/sendSecret keymessage + audience → {sent, failed, total}
GET /push/statsSecret key{subscribers, users, sentToday, topics}

Limits & behaviour

  • Default 5000 pushes / project / day (admin adjustable).
  • Expired subscriptions (HTTP 404/410) are removed automatically; 5 consecutive failures pause a subscription.
  • Payloads are encrypted end-to-end (RFC 8291); push services (Google/Mozilla/Apple) cannot read them.
  • iOS requires the site to be installed to the Home Screen (PWA) first.

Was this page helpful? Tell us. · Download SDK