> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt # Set up push notifications Canonical URL: https://posthog.com/docs/workflows/push > **Cloud region:** This page uses US Cloud hosts. For an EU Cloud project, use `https://eu.posthog.com` instead of `https://app.posthog.com` (app host for links). ## On this page - [Connect a push channel](#connect-a-push-channel) - [Register devices](#register-devices) - [Track opens](#track-opens) - [Verify device identity](#verify-device-identity) - [Send a push](#send-a-push) - [Pricing](#pricing) - [Troubleshooting](#troubleshooting) Send push notifications to your iOS and Android apps from [automations](https://posthog.com/docs/workflows/automations.md) and [broadcasts](https://posthog.com/docs/workflows/broadcasts/push.md). Setup has three parts: 1. [Connect a push channel](#connect-a-push-channel) with your Firebase or Apple credentials. 2. [Register devices](#register-devices) with the PostHog mobile SDK. 3. [Send a push](#send-a-push) from a broadcast or an automation. Your app still owns its platform push setup. You turn on push with Firebase or Apple, and you ask the user for notification permission. The PostHog SDK reads the device token that your app gets, stores it on the person in PostHog, and captures an event when someone opens a notification. ## Connect a push channel Pick the provider that your app sends through: - **Firebase Cloud Messaging (FCM)** for Android, and for iOS apps that send through Firebase. - **Apple Push Notifications (APNs)** for iOS apps that send to Apple directly. On the [**Channels** tab](https://app.posthog.com/workflows/channels), click **Connect** on the provider's card. To connect a channel, change it, or change its identity verification, you need project admin access. ![The Channels tab with the Firebase Cloud Messaging and Apple Push Notifications cards and their Connect buttons](https://res.cloudinary.com/dmukukwp6/image/upload/w_1600,c_limit,q_auto,f_auto/channel_catalog_push_light_4934ccd69f.png) ### Firebase Cloud Messaging Paste your Firebase service account key into **Service account key JSON**. To create a key, open the [Firebase console](https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk) and go to **Project settings** > **Service accounts** > **Generate new private key**. PostHog reads your Firebase project ID from the key. ![The Configure Firebase Cloud Messaging form with the service account key field and the Identity verification selector](https://res.cloudinary.com/dmukukwp6/image/upload/w_1600,c_limit,q_auto,f_auto/fcm_channel_setup_light_d9f85d9771.png) ### Apple Push Notifications Create an APNs auth key in your [Apple Developer account](https://developer.apple.com/account/resources/authkeys/list), under **Certificates, Identifiers & Profiles** > **Keys**. Then fill in the form: | Field | What to enter | | --- | --- | | **Signing key (.p8)** | The key file you downloaded from Apple. Paste its contents or upload the file. | | **Key ID** | The ID of the signing key. | | **Apple team ID** | Your Apple developer team ID. | | **Bundle ID** | Your app's bundle identifier, such as `com.example.app`. | | **Environment** | **Production** for App Store and TestFlight builds. **Sandbox** for builds that you run from Xcode. | To send to both kinds of builds, connect the same app twice, once for each environment. ![The Configure Apple Push Notification Service form with all five fields and the Identity verification selector](https://res.cloudinary.com/dmukukwp6/image/upload/w_1600,c_limit,q_auto,f_auto/apns_channel_setup_light_bc9750dd85.png) Both forms also have an **Identity verification** setting. Keep it on **Disabled** until your app sends identity tokens. See [verify device identity](#verify-device-identity). ## Register devices Follow the guide for your SDK: - [iOS](https://posthog.com/docs/workflows/push/ios.md) - [Android](https://posthog.com/docs/workflows/push/android.md) - [React Native](https://posthog.com/docs/workflows/push/react-native.md) - [Flutter](https://posthog.com/docs/workflows/push/flutter.md) Every SDK registers devices the same way: - **It registers automatically.** The SDK registers the device token under the current distinct ID, so the device moves to the user when you call `identify()`. When you call `reset()` at sign-out, the SDK removes the device from the signed-out user and registers it under the new anonymous ID. - **It sends an app ID with each device.** The app ID is your Firebase project ID for FCM, or your bundle ID for APNs. PostHog stores the device only when a channel in the project has that app ID, and drops it otherwise. Connect the channel first. Devices that start before you connect it register when the SDK next loads its config. - **It retries.** If the device is offline or a request fails, the SDK tries again on the next flush, identity change, or app launch. ### iOS apps that send through Firebase If your iOS app sends through FCM, turn off automatic registration and register the FCM token yourself, with your Firebase project ID as the app ID. If you leave automatic registration on, the SDK also registers the APNs token under your bundle ID. The device then has two registrations, and a push that uses both channels arrives twice. ### Devices from another provider The SDK registers a device when a user opens a version of your app that includes it. To reach devices that registered with your old provider before then, [import your device tokens](https://posthog.com/docs/workflows/push/import-device-tokens.md). ## Track opens When someone taps a notification, the SDK captures a `$push_notification_opened` event. It can include `$notification_title`, `$notification_subtitle` (iOS only), and `$notification_body`, plus `$notification_action` when the person taps an action button. - On iOS, the SDK adds the title, subtitle, and body only for notifications that PostHog sent. - On Android, an open that the SDK captures automatically has no title or body, because Firebase removes them from the intent that it gives your app. - Automatic capture can't see notifications that your app schedules or draws itself. Capture those with the SDK's manual `capturePushNotificationOpened` call. - In recent SDK versions, the manual call skips a notification that PostHog sent if the SDK already captured the same tap in the last 5 minutes. Each SDK guide gives the version. Opens of notifications from other providers are never deduplicated. To keep notification content out of your events, see [protect sensitive data](https://posthog.com/docs/workflows/push/push-step-options.md#protect-sensitive-data). ## Verify device identity A device token says where to deliver a notification. It doesn't say who owns the device. Your project token is public, so without identity verification, anyone who has it can register a device for any distinct ID. With identity verification, your backend signs a short-lived token for the signed-in user. The app sends that token when it registers or unregisters the device, and PostHog checks it. 1. Generate an EC P-256 key pair once. Keep the private key on your backend: ```bash openssl ecparam -name prime256v1 -genkey -noout -out push-identity-private.pem openssl ec -in push-identity-private.pem -pubout -out push-identity-public.pem ``` 2. On your backend, sign an ES256 JWT with the private key. PostHog accepts only ES256. The token needs these claims: | Claim | Value | | --- | --- | | `sub` | The user's distinct ID | | `app_id` | The app ID that the SDK sends: your Firebase project ID or your bundle ID | | `aud` | `posthog:push_identity` | | `exp` | An expiry time a few minutes ahead. PostHog rejects a token without one. | For example, in Node.js with `jsonwebtoken`: ```javascript import jwt from "jsonwebtoken" const token = jwt.sign( { sub: distinctId, app_id: appId, aud: "posthog:push_identity" }, privateKeyPem, { algorithm: "ES256", expiresIn: "5m" } ) ``` 3. In your app, return the token from the SDK's `pushIdentityProvider` callback. Each SDK guide shows the syntax. The SDK keeps the token in memory for each distinct ID and app ID, and asks again when the identity changes or PostHog rejects the token. If your callback doesn't answer in 10 seconds, the SDK sends the request without a token. 4. Edit the channel. Paste the contents of the public key file into **Public key**, and set **Identity verification** to **Optional**. PostHog checks each token, but still registers devices without a valid one. 5. When your app sends valid tokens, set **Identity verification** to **Required**. PostHog then rejects a registration or unregistration without a valid token, with a `401`. ## Send a push - In an automation, add a **Push** step. See [push step settings](https://posthog.com/docs/workflows/push/push-step-options.md). - To send once to an audience, use a [push broadcast](https://posthog.com/docs/workflows/broadcasts/push.md). Each person gets the notification on the devices that they registered with the channels you pick. PostHog skips people who have no registered device. See [limits](https://posthog.com/docs/workflows/reference/limits.md#api-and-sdk-limits) for how many channels and devices one send reaches. ## Pricing A push step that reaches at least one of a person's devices counts as one dispatch under push and other destinations, however many devices it reaches. A push that reaches no device isn't billed. PostHog stores each device on its person with a `$set` event. Each registration, and each imported device, counts as one Product Analytics event. See [pricing](https://posthog.com/pricing.md). ## Troubleshooting | Problem | What to check | | --- | --- | | The device never registers | The user granted notification permission, and your app registers for push with Firebase or Apple. The channel's Firebase project ID or bundle ID matches your app. | | Registration fails with a `401` | The channel requires identity verification. Your `pushIdentityProvider` must return a token in 10 seconds, signed with the key that pairs with the channel's public key, with the correct `sub` and `app_id`, and not expired. | | A push never arrives on iOS | The APNs channel's **Environment** matches your build, and its **Bundle ID** matches your app. | | An iOS device gets each push twice | The device registered with both your APNs and FCM channels. See [iOS apps that send through Firebase](#ios-apps-that-send-through-firebase). |