> 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/flutter ## On this page - [Requirements](#requirements) - [Register the device](#register-the-device) - [Capture opens](#capture-opens) - [Identity verification](#identity-verification) - [Opt out](#opt-out) - [Troubleshooting](#troubleshooting) Register iOS and Android devices for [push notifications](https://posthog.com/docs/workflows/push.md) with the PostHog Flutter SDK, and capture when users open them. Before you start, [connect a push channel](https://posthog.com/docs/workflows/push.md#connect-a-push-channel). ## Requirements - Flutter SDK 5.35.0 or later. Later sections give the versions that some features need. - Push set up in your app, for example with `firebase_messaging`, and notification permission from the user. - iOS 14 or later for automatic registration and open capture on iOS. Push isn't supported on Flutter web, macOS, Windows, or Linux. > **CocoaPods is becoming read-only.** [CocoaPods trunk becomes read-only on December 2, 2026](https://blog.cocoapods.org/CocoaPods-Specs-Repo/), and `posthog-ios` 4.0 and later is only published through Swift Package Manager (SPM). > > `posthog_flutter` 6.0 and later uses `posthog-ios` 4.0 and installs on iOS and macOS through SPM only. It has no podspec. It needs Xcode 26 or later, iOS 15, and macOS 12. Flutter 3.44 and later turn SPM on by default. See the [Flutter migration guide](https://posthog.com/docs/libraries/flutter/migration.md). > > `posthog_flutter` 5.x stays on `posthog-ios` 3.x through CocoaPods or SPM. If your app can't use SPM, stay on 5.x. That includes a Flutter module embedded in an iOS app on Flutter earlier than 3.50, which installs module plugins with CocoaPods. > > `posthog_flutter` 6.0 also needs Flutter 3.41 or later on every platform, including Android and web. `flutter pub get` fails on an older Flutter. ## Register the device The SDK registers the device and captures opens by default: ```dart final config = PostHogConfig(''); // Both default to true config.capturePushNotificationSubscriptions = true; // register the device token config.capturePushNotificationOpened = true; // capture $push_notification_opened await Posthog().setup(config); ``` On iOS, the SDK registers the APNs token under your bundle ID when your app registers for remote notifications. On Android, it fetches the FCM token at startup and registers it under your Firebase project ID. **iOS needs a notification delegate** iOS reports a notification tap only to `UNUserNotificationCenter.current().delegate`. A new Flutter app doesn't set one, and neither does `flutter_local_notifications`. Without it, the SDK can't capture any opens on iOS. 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) } ``` With `debug = true` on `PostHogConfig`, the SDK logs a warning if the delegate is still missing shortly after setup. The Android startup fetch doesn't see later token changes, so forward them: ```dart if (Platform.isAndroid) { FirebaseMessaging.instance.onTokenRefresh.listen( (token) => Posthog().registerPushNotificationToken(token), ); } ``` ### Register manually If you manage tokens yourself, set `capturePushNotificationSubscriptions` to `false` and register the token after `setup()` completes. The SDK drops a token that you register earlier, without an error. ```dart await Posthog().registerPushNotificationToken(token); ``` Without an `appId`, iOS registers an APNs token under your bundle ID, and Android registers an FCM token under your Firebase project ID. To register an FCM token on iOS, pass your Firebase project ID. See [iOS apps that send through Firebase](https://posthog.com/docs/workflows/push.md#ios-apps-that-send-through-firebase). ```dart await Posthog().registerPushNotificationToken(token, appId: 'your-firebase-project-id'); ``` If you don't call `Posthog().reset()` at sign-out, unregister the device yourself: ```dart await Posthog().unregisterPushNotificationToken(); ``` ## Capture opens From Flutter SDK 5.40.0, the SDK captures every tap on a remote notification, on both platforms, whether it launches the app or arrives while the app runs. From 5.42.1, an Android tap that arrives before `Posthog().setup()` runs is captured once setup completes. On Android, the SDK recognizes a tap by the `google.message_id` extra that Firebase puts on the intent, so it can't see push delivered outside FCM. It also can't see locally scheduled notifications, or notifications that your app draws from a foreground message. Capture those yourself: ```dart Posthog().capturePushNotificationOpened( title: 'Your order shipped', body: 'Track it in the app', payload: {'order_id': '1234'}, ); ``` Don't call it from `FirebaseMessaging.onMessageOpenedApp` or `getInitialMessage()`, because the SDK already captures those taps. From Flutter SDK 5.43.1, the manual call skips a notification that PostHog sent if the SDK captured it in the last 5 minutes. A handler that you add for other notifications still counts them twice. ## Identity verification If your channel uses [identity verification](https://posthog.com/docs/workflows/push.md#verify-device-identity), return a token from your backend through `pushIdentityProvider`: ```dart config.pushIdentityProvider = (distinctId, appId) async { // Get a token for this user from your backend, then: return token; // or null to send without one }; ``` `pushIdentityProvider` is a Dart callback, so it has no `Info.plist` or manifest setting. If your app uses `com.posthog.posthog.AUTO_INIT`, set it to `false` and call `Posthog().setup()` yourself. Otherwise the SDK never installs the callback. ## Opt out Set `capturePushNotificationSubscriptions` or `capturePushNotificationOpened` to `false` on `PostHogConfig` before `setup()`. On iOS, the SDK installs a launch hook before any Dart runs, so `capturePushNotificationOpened = false` stops the event but not the hook. To skip the hook, set `com.posthog.posthog.CAPTURE_PUSH_NOTIFICATION_OPENED` to `false` in `Info.plist`. If your app sets up the SDK natively with `com.posthog.posthog.AUTO_INIT`, the Dart config doesn't apply. Set the `com.posthog.posthog.CAPTURE_PUSH_NOTIFICATION_SUBSCRIPTIONS` and `com.posthog.posthog.CAPTURE_PUSH_NOTIFICATION_OPENED` keys to `false` instead, in `Info.plist` on iOS and as `` in `AndroidManifest.xml` on Android. ## Troubleshooting | Problem | What to check | | --- | --- | | The token never registers | On Android, `firebase-messaging` is on the classpath, which `firebase_messaging` sets up. A manual `registerPushNotificationToken` call comes after `setup()` completes. | | Opens aren't captured on iOS | Your `AppDelegate` sets `UNUserNotificationCenter.current().delegate`, and the device runs iOS 14 or later. | | Opens aren't captured on Android | The push goes through FCM, and your launcher activity has `android:launchMode="singleTop"`. Without it, the system resumes the task and doesn't deliver the tap. | For problems that apply to every SDK, see [push troubleshooting](https://posthog.com/docs/workflows/push.md#troubleshooting).