Replace EventLogger with typed AnalyticsManager using PostHog

Complete analytics overhaul: delete EventLogger.swift, create Analytics.swift
with typed event enum (~45 events), screen tracking, super properties
(theme, icon pack, voting layout, etc.), session replay with kill switch,
autocapture, and network telemetry. Replace all 99 call sites across 38 files
with compiler-enforced typed events in object_action naming convention.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-02-10 15:12:33 -06:00
parent a08d0d33c0
commit e0330dbc8d
38 changed files with 1048 additions and 202 deletions

View File

@@ -98,12 +98,12 @@ class BiometricAuthManager: ObservableObject {
isUnlocked = success
if success {
EventLogger.log(event: "biometric_unlock_success")
AnalyticsManager.shared.track(.biometricUnlockSuccess)
}
return success
} catch {
print("Authentication failed: \(error.localizedDescription)")
EventLogger.log(event: "biometric_unlock_failed", withData: ["error": error.localizedDescription])
AnalyticsManager.shared.track(.biometricUnlockFailed(error: error.localizedDescription))
// If biometrics failed, try device passcode as fallback
if canUseDevicePasscode && policy == .deviceOwnerAuthenticationWithBiometrics {
@@ -136,7 +136,7 @@ class BiometricAuthManager: ObservableObject {
func lock() {
guard isLockEnabled else { return }
isUnlocked = false
EventLogger.log(event: "app_locked")
AnalyticsManager.shared.track(.appLocked)
}
func enableLock() async -> Bool {
@@ -159,7 +159,7 @@ class BiometricAuthManager: ObservableObject {
if success {
isLockEnabled = true
isUnlocked = true
EventLogger.log(event: "privacy_lock_enabled")
AnalyticsManager.shared.track(.privacyLockEnabled)
}
return success
@@ -172,6 +172,6 @@ class BiometricAuthManager: ObservableObject {
func disableLock() {
isLockEnabled = false
isUnlocked = true
EventLogger.log(event: "privacy_lock_disabled")
AnalyticsManager.shared.track(.privacyLockDisabled)
}
}

View File

@@ -45,6 +45,12 @@ class ExportService {
.horrible: UIColor(red: 0.91, green: 0.30, blue: 0.24, alpha: 1.0) // Red
]
private func trackDataExported(format: String, count: Int) {
Task { @MainActor in
AnalyticsManager.shared.track(.dataExported(format: format, count: count))
}
}
// MARK: - CSV Export
func generateCSV(entries: [MoodEntryModel]) -> String {
@@ -75,7 +81,7 @@ class ExportService {
do {
try csv.write(to: tempURL, atomically: true, encoding: .utf8)
EventLogger.log(event: "csv_exported", withData: ["count": entries.count])
trackDataExported(format: "csv", count: entries.count)
return tempURL
} catch {
print("ExportService: Failed to write CSV: \(error)")
@@ -152,7 +158,7 @@ class ExportService {
drawFooter(pageWidth: pageWidth, pageHeight: pageHeight, margin: margin, in: context)
}
EventLogger.log(event: "pdf_exported", withData: ["count": entries.count])
trackDataExported(format: "pdf", count: entries.count)
return data
}

View File

@@ -79,11 +79,11 @@ class HealthService: ObservableObject {
try await healthStore.requestAuthorization(toShare: [], read: readTypes)
isAuthorized = true
isEnabled = true
EventLogger.log(event: "healthkit_authorized")
AnalyticsManager.shared.track(.healthKitAuthorized)
return true
} catch {
print("HealthService: Authorization failed: \(error.localizedDescription)")
EventLogger.log(event: "healthkit_auth_failed", withData: ["error": error.localizedDescription])
AnalyticsManager.shared.track(.healthKitAuthFailed(error: error.localizedDescription))
return false
}
}

View File

@@ -95,7 +95,7 @@ class PhotoManager: ObservableObject {
try? thumbnailData.write(to: thumbnailURL)
}
EventLogger.log(event: "photo_saved")
AnalyticsManager.shared.track(.photoAdded)
return photoID
}
@@ -163,7 +163,7 @@ class PhotoManager: ObservableObject {
}
if success {
EventLogger.log(event: "photo_deleted")
AnalyticsManager.shared.track(.photoDeleted)
}
return success