Web
Prerequisites: an app in Settings → Apps with a web client key for your origin, and Web Push keys. Read Concepts.
-
Install.
Terminal window npm install @mailpidge/lifecycle-sdk -
Create the client.
import { createMailPidgeLifecycleClient } from '@mailpidge/lifecycle-sdk'export const mailpidge = createMailPidgeLifecycleClient({ clientCredential: 'mpck_…', appId: 'pidgefit-web' }) -
Identify after sign-in; reset on sign-out.
await mailpidge.identify(user.id, { plan: user.plan }, { identityToken })await mailpidge.reset() -
Track events.
await mailpidge.track('workout_completed', { minutes: 42 }) -
Serve
node_modules/@mailpidge/lifecycle-sdk/service-worker/mailpidge-sw.jsat/mailpidge-sw.js. -
Subscribe to push from a user action.
const registration = await navigator.serviceWorker.register('/mailpidge-sw.js')const pushSubscription = await registration.pushManager.subscribe({userVisibleOnly: true,applicationServerKey: 'BOr0…vX9c', // Settings → Apps → Web → Public key})await mailpidge.registerWebPushSubscription(pushSubscription.toJSON()) -
Record consent.
await mailpidge.setChannelConsent({ channel: 'push', status: 'opted_in', consentLanguageShown: 'Send me workout tips' })
Settings → Apps → your app → Send test push. The notification appears and the browser shows as Active.
iPhone and iPad receive web push only after the site is added to the Home Screen.