triggair
Guides

Web push notifications

Re-engage players with self-hosted Web Push (VAPID): subscribe from the game, send from the dashboard/MCP to everyone, a segment, or one player.

Push notifications bring players back: a reward is ready, it's their turn, a live event started. Triggair uses standards-based Web Push (VAPID): no third-party vendor, no per-message cost, and the same delivery whether the browser's push service is Chrome's, Firefox's, or Safari's.

Subscribing (in the game)

Web Push needs a service worker in your app (it's what shows the notification). Register it, then call tg.push.subscribe(): the SDK fetches the game's VAPID key, asks the browser to subscribe, and registers it server-side. Subscribing is refused for minors and age-unknown players by the behavioral_push compliance gate (the same gate that guards other regulated features), so screen age first with tg.compliance.setAge.

await navigator.serviceWorker.register('/sw.js');
try {
  await tg.push.subscribe();
} catch (e) {
  // age_restricted / parental_consent_required for minors — offer the age screen
}

The service worker

Your service worker receives the push and shows it. The payload is JSON: { title, body?, url?, icon? }.

self.addEventListener('push', (e) => {
  const n = e.data.json();
  e.waitUntil(self.registration.showNotification(n.title, { body: n.body, icon: n.icon, data: n }));
});
self.addEventListener('notificationclick', (e) => {
  e.notification.close();
  if (e.notification.data?.url) e.waitUntil(clients.openWindow(e.notification.data.url));
});

Sending (dashboard / MCP)

Send from the dashboard Push panel or the triggair_send_push MCP tool: a title + optional body/url, targeted at everyone, a materialized segment (reuse your LiveOps segments), or a single player. Delivery returns { sent, failed, removed }: dead subscriptions are pruned automatically, so your list stays clean. Sending is a server/operator action; the game never sends push to itself.

More in Content and LiveOps

← All guides · Recipes · API reference