feat: add PostHog analytics with full event tracking across app

Integrate self-hosted PostHog (SPM) with AnalyticsManager singleton wrapping
all SDK calls. Adds ~40 type-safe events covering trip planning, schedule,
progress, IAP, settings, polls, export, and share flows. Includes session
replay, autocapture, network telemetry, privacy opt-out toggle in Settings,
and super properties (app version, device, pro status, selected sports).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-02-10 15:12:16 -06:00
parent 5389fe3759
commit 2917ae22b1
20 changed files with 989 additions and 23 deletions

View File

@@ -14,7 +14,9 @@ final class SettingsViewModel {
var selectedTheme: AppTheme {
didSet {
let oldName = oldValue.displayName
ThemeManager.shared.currentTheme = selectedTheme
AnalyticsManager.shared.track(.themeChanged(from: oldName, to: selectedTheme.displayName))
}
}
@@ -23,7 +25,10 @@ final class SettingsViewModel {
}
var maxDrivingHoursPerDay: Int {
didSet { savePreferences() }
didSet {
savePreferences()
AnalyticsManager.shared.track(.drivingHoursChanged(hours: maxDrivingHoursPerDay))
}
}
// MARK: - App Info
@@ -63,8 +68,10 @@ final class SettingsViewModel {
// Don't allow removing all sports
guard selectedSports.count > 1 else { return }
selectedSports.remove(sport)
AnalyticsManager.shared.track(.sportToggled(sport: sport.rawValue, enabled: false))
} else {
selectedSports.insert(sport)
AnalyticsManager.shared.track(.sportToggled(sport: sport.rawValue, enabled: true))
}
}
@@ -73,6 +80,7 @@ final class SettingsViewModel {
selectedSports = Set(Sport.supported)
maxDrivingHoursPerDay = 8
AppearanceManager.shared.currentMode = .system
AnalyticsManager.shared.track(.settingsReset)
}
// MARK: - Persistence