Skill 76 · Instrument Error Tracking
Subchapter 76.14
references/ios.mdMarkdown6 KBView on GitHub
AI agents: this is one page from PostHog’s docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt (opens in a new tab)
1
Required
Install via Swift Package Manager:
Package.swift
dependencies: [
.package(url: "https://github.com/PostHog/posthog-ios.git", from: "3.56.0")
]Or add PostHog to your Podfile:
Podfile
pod "PostHog", "~> 3.56"2
Required
Initialize PostHog in your AppDelegate:
AppDelegate.swift
import Foundation
import PostHog
import UIKit
class AppDelegate: NSObject, UIApplicationDelegate {
func application(
3
Recommended
Once installed, PostHog will automatically start capturing events. You can also manually send events to test your integration:
Swift
PostHogSDK.shared.capture("button_clicked", properties: ["button_name": "signup"])4
Recommended
Remote configuration
Exception autocapture can also be managed remotely via the error tracking settings (opens in a new tab).
Platform support
Exception 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.autoCapture argument to true when initializing the PostHog SDK.
Swift
import PostHog
let config =
5
Optional
You can manually capture exceptions using the captureException method:
Swift
import PostHog
do {
try FileManager.default.removeItem(
6
Optional
By 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:
Swift
import PostHog
let config = PostHogConfig(
projectToken: "<ph_project_token>",
host: "https://us.i.posthog.com"
Recommended
Confirm events are being sent to PostHog
Before proceeding, let’s make sure exception events are being captured and sent to PostHog. You should see events appear in the activity feed.

7
Required
Great, you’re capturing exceptions! The next step is to upload dSYM files so PostHog can symbolicate your crash reports and generate accurate stack traces.
Let’s continue to the next section.
SIGTRAP without the actual error message (issue (opens in a new tab)).Ask PostHog AI
HelpfulCould be better
When enabled, this automatically captures $exception events for:
EXC_BAD_ACCESS, EXC_CRASH)SIGSEGV, SIGABRT, SIGBUS)Crashes are persisted to disk and sent as $exception events with level “fatal” on the next app launch.
For Objective-C code that uses NSException:
Objective-C
@import PostHog;
@try {
[self riskyOperation];
} @catch (NSException *exception) {
[[PostHogSDK shared] captureExceptionWithNSException:exception properties:nil];
}You can add custom properties to help with debugging, grouping, and analysis:
Swift
do {
try performNetworkRequest()
} catch {
PostHogSDK.shared.captureException(error, properties: [
"endpoint": "/api/users",
"retry_count": 3
])
}This is helpful if you’ve built your own error handling logic or want to capture exceptions that are handled by your application code.
Configuration options:
| Option | Description |
|---|---|
inAppIncludes | List of package/bundle identifiers to mark as in-app (takes precedence over excludes) |
inAppExcludes | List of package/bundle identifiers to exclude from in-app |
inAppByDefault | Whether frames are considered in-app by default when origin cannot be determined |
Default behavior: