fix: permanently fix PostHog module emission error
Some checks failed
PR → Build → Firebase OTA → LGTM / Build & Deploy to Firebase OTA (pull_request) Failing after 0s
PR → Build → Firebase OTA → LGTM / Wait for LGTM comment (pull_request) Has been skipped

- Change PostHog from exactVersion to revision (tag 3.62.0) in project.yml
- Add deep cache clean step before xcodegen in CI workflow
- Add ONLY_ACTIVE_ARCH=NO to xcodebuild command
- Wrap PostHog usage in #if canImport(PostHog) for graceful degradation
- Add Package.resolved, .build/, DerivedData/ to .gitignore
- Remove stale SPM caches between CI runs (DerivedData, swiftpm caches, act cache)
This commit is contained in:
2026-06-27 00:39:52 +00:00
parent 9739a739f5
commit 58177102a4
4 changed files with 25 additions and 1 deletions

View File

@@ -1,30 +1,38 @@
import Foundation
#if canImport(PostHog)
import PostHog
#endif
/// PostHog analytics mirrors the event taxonomy from the Expo app.
final class AnalyticsService: @unchecked Sendable {
static let shared = AnalyticsService()
#if canImport(PostHog)
private let apiKey: String =
Bundle.main.infoDictionary?["POSTHOG_API_KEY"] as? String ?? ""
private let host = "https://eu.posthog.com"
#endif
private init() {}
func initialize() {
#if canImport(PostHog)
guard !apiKey.isEmpty else { return }
let config = PostHogConfig(apiKey: apiKey, host: host)
config.captureApplicationLifecycleEvents = true
config.captureScreenViews = false // manual tracking
PostHogSDK.shared.setup(config)
#endif
}
// Screens
func screen(_ name: String, properties: [String: Any] = [:]) {
#if canImport(PostHog)
PostHogSDK.shared.screen(name, properties: properties)
#endif
}
// Onboarding
@@ -100,6 +108,8 @@ final class AnalyticsService: @unchecked Sendable {
// Private
private func capture(_ event: String, properties: [String: Any] = [:]) {
#if canImport(PostHog)
PostHogSDK.shared.capture(event, properties: properties.isEmpty ? nil : properties)
#endif
}
}