iOS error tracking installation
- 1
Install dependency
RequiredExperimental APIError tracking is currently experimental. You need to import PostHog with the
ExperimentalSPI group:@_spi(Experimental) import PostHogInstall via Swift Package Manager:
Package.swiftOr add PostHog to your Podfile:
Podfile - 2
Configure PostHog
RequiredInitialize PostHog in your AppDelegate:
AppDelegate.swift - 3
Send events
RecommendedOnce installed, PostHog will automatically start capturing events. You can also manually send events to test your integration:
Swift - 4
Set up exception autocapture
RecommendedRemote configurationException autocapture can also be managed remotely via the error tracking settings.
Platform supportException autocapture is available on iOS, macOS, and tvOS only. It is not available on watchOS or visionOS due to platform limitations.
You can still capture events manually on all platforms, including visionOS.
You can autocapture exceptions by setting the
errorTrackingConfig.autoCaptureargument totruewhen initializing the PostHog SDK.SwiftWhen enabled, this automatically captures
$exceptionevents for:- Mach exceptions (e.g.,
EXC_BAD_ACCESS,EXC_CRASH) - POSIX signals (e.g.,
SIGSEGV,SIGABRT,SIGBUS) - Uncaught NSExceptions
Crashes are persisted to disk and sent as
$exceptionevents with level "fatal" on the next app launch. - Mach exceptions (e.g.,
- 5
Manually capture exceptions
OptionalSwift Error handling
You can manually capture exceptions using the
captureExceptionmethod:SwiftObjective-C NSException handling
For Objective-C code that uses NSException:
Objective-CAdding custom properties
You can add custom properties to help with debugging, grouping, and analysis:
SwiftThis is helpful if you've built your own error handling logic or want to capture exceptions that are handled by your application code.
- 6
Configure in-app frames
OptionalBy default, PostHog automatically marks your app's code as "in-app" in stack traces to help you focus on your code rather than system frameworks.
You can customize this behavior with
errorTrackingConfig:SwiftConfiguration options:
Option Description inAppIncludesList of package/bundle identifiers to mark as in-app (takes precedence over excludes) inAppExcludesList of package/bundle identifiers to exclude from in-app inAppByDefaultWhether frames are considered in-app by default when origin cannot be determined Default behavior:
- Your app's bundle identifier and executable name are automatically included
- System frameworks (Foundation, UIKit, etc.) are automatically excluded
- 7

