Flutter error tracking installation
Contents
We currently don't support the following features:
- Automatic exception capture
- De-obfuscating stacktraces from obfuscated builds (--obfuscate and --split-debug-info)
- Source code context associated with an exception
- Flutter web support
These features will be added in future releases.
- 1
Install PostHog Flutter SDK
RequiredSDK version requirementA minimum SDK version of 5.7.0 is required, but we recommend keeping up to date with the latest version to ensure you have all of error tracking's features.
PostHog is available for install via Pub.
Configuration
Set your PostHog API key and change the automatic event tracking on if you wish the library to take care of it for you.
Remember that the application lifecycle events won't have any special context set for you by the time it is initialized. If you are using a self-hosted instance of PostHog you will need to have the public hostname or IP for your instance as well.
To start, add
posthog_flutterto yourpubspec.yaml:pubspec.yamlThen complete the set up for each platform:
For Session replay and Surveys you must setup the SDK manually by disabling the
com.posthog.posthog.AUTO_INITmode.Android setup
There are 2 ways of initializing the SDK, automatically and manually.
Automatically:
Add your PostHog configuration to your
AndroidManifest.xmlfile located in theandroid/app/src/main:android/app/src/main/AndroidManifest.xmlOr manually (more control and more configurations available):
Add your PostHog configuration to your
AndroidManifest.xmlfile located in theandroid/app/src/main:android/app/src/main/AndroidManifest.xmlIn both cases, you'll also need to update the minimum Android SDK version to
21inandroid/app/build.gradle:android/app/build.gradleiOS setup
There are 2 ways of initializing the SDK, automatically and manually.
You'll need to have Cocoapods installed.
Automatically:
Add your PostHog configuration to the
Info.plistfile located in theios/Runnerdirectory:ios/Runner/Info.plistOr manually (more control and more configurations available):
Add your PostHog configuration to the
Info.plistfile located in theios/Runnerdirectory:ios/Runner/Info.plistIn both cases, you'll need to set the minimum platform version to iOS 13.0 in your Podfile:
ios/PodfileDart setup (For manual step only)
If you followed the automatic SDK setup, then there's no more configuration needed in Dart.
If you followed the manual SDK setup:
DartWeb setup
For Web, add your
Web snippet(which you can find in your project settings) in the<header>of yourweb/index.htmlfile:web/index.htmlFor more information please check: /docs/libraries/js
- 2
Manually capture exceptions
OptionalBasic usage
You can manually capture exceptions using the
captureExceptionmethod:DartThis is helpful if you've built your own error handling logic or want to capture exceptions that are handled by your application code.
Error tracking configuration
You can configure error tracking behavior when setting up PostHog:
DartConfiguration options:
inAppIncludes: List of package names to be considered inApp frames (takes precedence over excludes)inAppExcludes: List of package names to be excluded from inApp framesinAppByDefault: Whether frames are considered inApp by default when their origin cannot be determined
inAppframes are stack trace frames that belong to your application code (as opposed to third-party libraries or system code). These are highlighted in the PostHog error tracking interface to help you focus on the relevant parts of the stack trace.

