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

@@ -9,7 +9,6 @@ import SwiftUI
import SwiftData
import BackgroundTasks
import WidgetKit
import PostHog
@main
struct FeelsApp: App {
@@ -24,12 +23,7 @@ struct FeelsApp: App {
@State private var showSubscriptionFromWidget = false
init() {
// Initialize PostHog analytics
let posthogConfig = PostHogConfig(apiKey: "phc_3GsB3oqNft8Ykg2bJfE9MaJktzLAwr2EPMXQgwEFzAs", host: "https://analytics.88oakapps.com")
#if DEBUG
posthogConfig.debug = true
#endif
PostHogSDK.shared.setup(posthogConfig)
AnalyticsManager.shared.configure()
BGTaskScheduler.shared.cancelAllTaskRequests()
BGTaskScheduler.shared.register(forTaskWithIdentifier: BGTask.updateDBMissingID, using: nil) { (task) in
@@ -59,7 +53,7 @@ struct FeelsApp: App {
.environmentObject(authManager)
.environmentObject(healthKitManager)
.sheet(isPresented: $showSubscriptionFromWidget) {
FeelsSubscriptionStoreView()
FeelsSubscriptionStoreView(source: "widget_deeplink")
.environmentObject(iapManager)
}
.onOpenURL { url in
@@ -78,6 +72,8 @@ struct FeelsApp: App {
if newPhase == .background {
BGTask.scheduleBackgroundProcessing()
WidgetCenter.shared.reloadAllTimelines()
// Flush pending analytics events
AnalyticsManager.shared.flush()
// Lock the app when going to background
authManager.lock()
}
@@ -106,8 +102,8 @@ struct FeelsApp: App {
// Reschedule notifications for new title
LocalNotification.rescheduleNotifiations()
// Log event
EventLogger.log(event: "app_foregorund")
// Update super properties on foreground
AnalyticsManager.shared.updateSuperProperties()
}
// Defer Live Activity scheduling (heavy DB operations)
@@ -123,36 +119,7 @@ struct FeelsApp: App {
// Check subscription status (network call) - throttled
Task.detached(priority: .background) {
await iapManager.checkSubscriptionStatus()
// Set PostHog person properties for subscription segmentation
let state = await iapManager.state
let subscriptionStatus: String
let subscriptionType: String
switch state {
case .subscribed:
subscriptionStatus = "subscribed"
subscriptionType = await iapManager.currentProduct?.id.contains("yearly") == true ? "yearly" : "monthly"
case .inTrial:
subscriptionStatus = "trial"
subscriptionType = "none"
case .trialExpired:
subscriptionStatus = "trial_expired"
subscriptionType = "none"
case .expired:
subscriptionStatus = "expired"
subscriptionType = "none"
case .unknown:
subscriptionStatus = "unknown"
subscriptionType = "none"
}
PostHogSDK.shared.capture("$set", properties: [
"$set": [
"subscription_status": subscriptionStatus,
"subscription_type": subscriptionType
]
])
await iapManager.trackSubscriptionAnalytics(source: "app_foreground")
}
}
}