> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt # Flutter push notifications Canonical URL: https://posthog.com/docs/workflows/push-notifications/flutter ## On this page - [Requirements](#requirements) - [Automatic registration and open tracking (default)](#automatic-registration-and-open-tracking-default) - [Manual registration](#manual-registration) - [Capturing opens](#capturing-opens) - [Opting out](#opting-out) - [Identity verification](#identity-verification) - [Troubleshooting](#troubleshooting) Set up [Workflows](https://posthog.com/docs/workflows.md) push notifications in the Flutter SDK. For the concept and channel setup, see [Push notifications](https://posthog.com/docs/workflows/push-notifications.md). Available in the Flutter SDK version 5.35.0 and newer. Not supported on Flutter Web or macOS. ## Requirements > **CocoaPods is becoming read-only.** [CocoaPods has announced](https://blog.cocoapods.org/CocoaPods-Specs-Repo/) the following schedule for its public specs repository: > > - November 2–6, 2026: A read-only dry run will prevent us from publishing new PostHog iOS SDK versions to CocoaPods. > - December 2, 2026 onward: The repository will be permanently read-only. New PostHog iOS SDK versions will only be available through Swift Package Manager (SPM). > > Existing native SDK versions will remain available through CocoaPods. To keep receiving native SDK updates on iOS and macOS, migrate your Flutter app to SPM. The `posthog_flutter` package supports SPM, and Flutter 3.44 and later enable it by default. On earlier Flutter versions that support SPM, or if you disabled it, run `flutter config --enable-swift-package-manager`, then rebuild your app. Follow [Flutter's SPM migration guide](https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-app-developers) for project setup and troubleshooting. > > This change does not affect `posthog_flutter` releases on pub.dev, Android, or web. Configure push in your app as usual (for example with `firebase_messaging`) and request notification permission from the user. ## Automatic registration and open tracking (default) Both behaviors are on by default. An app that already has push configured starts sending its device token to PostHog after upgrading, with no code change: ```dart final config = PostHogConfig(''); // Both default to true, shown here for clarity: config.capturePushNotificationSubscriptions = true; // register the device token with PostHog config.capturePushNotificationOpened = true; // capture `$push_notification_opened` on tap await Posthog().setup(config); ``` On iOS the native SDK hooks the app delegate's remote-notification registration callback, so it picks up the APNs token once your app registers for remote notifications. On Android it fetches the FCM token at startup when `firebase-messaging` is on the classpath. The token is registered under the current distinct ID, so it follows the user across `identify()`. Every tap on a remote notification is captured on both platforms, whether the notification cold-launched the app or it was already running. Requires the Flutter SDK 5.40.0 or newer, which is where both halves landed, and iOS 14 or newer on the iOS side – below that the native SDK installs no push hooks at all. Locally-scheduled notifications are ignored. Capture those manually (below). On Android a tap is recognized by the `google.message_id` extra that Firebase puts on the intent, so push delivered outside FCM isn't seen. On Android a tap that reaches the app before `Posthog().setup()` runs is held and captured once setup completes, so coverage doesn't depend on your FCM package refreshing the activity's intent. Requires the Flutter SDK 5.42.1 or newer. **iOS needs a notification delegate** iOS only reports a notification tap to your app through `UNUserNotificationCenter.current().delegate`. A stock Flutter app doesn't set one, and neither does `flutter_local_notifications`. Without it, `$push_notification_opened` is never captured on iOS, in any app state. Set the delegate in `ios/Runner/AppDelegate.swift`: ```swift import UserNotifications override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { UNUserNotificationCenter.current().delegate = self return super.application(application, didFinishLaunchingWithOptions: launchOptions) } ``` The SDK logs a warning when the delegate is still missing shortly after setup, if you set `debug = true` on `PostHogConfig`. The Android startup fetch doesn't see later token refreshes, so forward those yourself to keep the registered token current: ```dart if (Platform.isAndroid) { FirebaseMessaging.instance.onTokenRefresh.listen( (token) => Posthog().registerPushNotificationToken(token), ); } ``` ## Manual registration If you manage push tokens yourself, turn the automatic flags off and call the SDK directly: ```dart // Register the device token. Pass appId to route to a specific channel // (your Firebase project id, or APNs bundle id on iOS): await Posthog().registerPushNotificationToken(token, appId: 'your-firebase-project-id'); ``` Call this only after `setup()` has completed; a token registered earlier is silently dropped. Unregister the token when a user signs out so it isn't left bound to them: ```dart await Posthog().unregisterPushNotificationToken(); ``` Calling `Posthog().reset()` on logout already moves the registered token to the new anonymous identity, so this is only needed when you manage subscriptions yourself. Registration and unregistration are durable. If the device is offline or the request fails, the SDK retries on the next flush, identity change, or app launch. ## Capturing opens Taps on remote notifications are captured for you on the Flutter SDK 5.40.0 and newer. Automatic capture can't see locally-scheduled notifications, notifications you display yourself from a foreground message, or push delivered outside FCM on Android. Call the manual API only for those: ```dart Posthog().capturePushNotificationOpened( title: 'Your order shipped', body: 'Track it in the app', payload: {'order_id': '1234'}, ); ``` Don't wire this to `FirebaseMessaging.onMessageOpenedApp` or `getInitialMessage()`. The SDK already captures those taps. On Android and iOS, from the Flutter SDK 5.43.1, a repeat of a notification PostHog sent is skipped when the same notification was captured in the last 5 minutes. Notifications PostHog didn't send are never deduplicated, so a handler you wire up yourself still counts those opens twice. The `$push_notification_opened` event includes `$notification_title` and `$notification_body` (plus `$notification_subtitle` on iOS), and `$notification_action` for action-button taps. On iOS, notification content is only captured for notifications sent by PostHog. On Android, taps captured automatically carry no title or body, because Firebase strips the content from the intent; those properties are only set when you pass them to `Posthog().capturePushNotificationOpened` yourself. ## Opting out Set `capturePushNotificationSubscriptions: false` or `capturePushNotificationOpened: false` on `PostHogConfig` before `setup()`. If your app initializes the SDK natively via `com.posthog.posthog.AUTO_INIT`, the Dart config doesn't apply because the native SDK is already set up before any Dart runs. Opt out with the `com.posthog.posthog.CAPTURE_PUSH_NOTIFICATION_SUBSCRIPTIONS` and `com.posthog.posthog.CAPTURE_PUSH_NOTIFICATION_OPENED` keys instead, in `Info.plist` on iOS and as AndroidManifest `` on Android. ## Identity verification If your push channel requires [identity verification](https://posthog.com/docs/workflows/push-notifications.md#identity-verification), supply a backend-minted token through `pushIdentityProvider`: ```dart config.pushIdentityProvider = (distinctId, appId) async { // Fetch a freshly-minted token from your backend for this user, then: return token; // or null to send without one }; ``` `pushIdentityProvider` is a Dart callback with no `Info.plist` or manifest equivalent. If your app uses `com.posthog.posthog.AUTO_INIT`, set it to `false` and call `Posthog().setup()` explicitly, otherwise the provider is never installed. ## Troubleshooting | Issue | Check | | --- | --- | | Token never registers | Confirm push is set up in your app and the user granted notification permission. On Android, confirm `firebase-messaging` is on the classpath (`firebase_messaging` sets this up). Any manual `registerPushNotificationToken` call must come after `setup()` completes. | | Push doesn't arrive | Confirm the channel's Firebase project (Android) or APNs environment and bundle id (iOS) match your app. | | `$push_notification_opened` never fires | On iOS, confirm your `AppDelegate` sets `UNUserNotificationCenter.current().delegate`. On Android, confirm the notification is sent through FCM (detection keys on the `google.message_id` intent extra), and that your launcher activity still has `android:launchMode="singleTop"`, without which the system resumes the task instead of delivering the tap. | | Registration rejected on a Required channel | Your `pushIdentityProvider` isn't returning a valid token in time. See [Identity verification](https://posthog.com/docs/workflows/push-notifications.md#identity-verification). |