Disable autocapture and debug analytics per PostHog SwiftUI best practices

- Disable captureElementInteractions (UIKit-only, duplicates manual events)
- Disable captureScreenViews (meaningless SwiftUI names, duplicates trackScreen())
- Opt out entirely in DEBUG builds to prevent test data polluting production

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-03-10 22:40:27 -05:00
parent 5ec2dfa739
commit a1340b4deb

View File

@@ -67,10 +67,12 @@ final class AnalyticsManager {
// enabling accurate unique user counts without requiring identify() calls
config.personProfiles = .always
// Auto-capture
config.captureElementInteractions = true
// Auto-capture disabled for SwiftUI (PostHog docs recommend manual tracking)
// captureElementInteractions: UIKit-only, generates noisy $autocapture events
// captureScreenViews: produces meaningless SwiftUI internal names, duplicates manual trackScreen()
config.captureElementInteractions = false
config.captureApplicationLifecycleEvents = true
config.captureScreenViews = true
config.captureScreenViews = false
// Session replay
config.sessionReplay = sessionReplayEnabled
@@ -85,8 +87,7 @@ final class AnalyticsManager {
}
#if DEBUG
config.debug = true
config.flushAt = 1
config.optOut = true // Prevent debug/test data from polluting production analytics
#endif
PostHogSDK.shared.setup(config)