Skip to content
PreviewNot live yet. APIs and SDKs on these pages may change before launch.

Web

Prerequisites: an app in Settings → Apps with a web client key for your origin, and Web Push keys. Read Concepts.

  1. Install.

    Terminal window
    npm install @mailpidge/lifecycle-sdk
  2. Create the client.

    import { createMailPidgeLifecycleClient } from '@mailpidge/lifecycle-sdk'
    export const mailpidge = createMailPidgeLifecycleClient({ clientCredential: 'mpck_…', appId: 'pidgefit-web' })
  3. Identify after sign-in; reset on sign-out.

    await mailpidge.identify(user.id, { plan: user.plan }, { identityToken })
    await mailpidge.reset()
  4. Track events.

    await mailpidge.track('workout_completed', { minutes: 42 })
  5. Serve node_modules/@mailpidge/lifecycle-sdk/service-worker/mailpidge-sw.js at /mailpidge-sw.js.

  6. 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())
  7. 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.