Add PostHog analytics integration - #32
Draft
posthog-eu[bot] wants to merge 3 commits into
Draft
Conversation
Generated-By: PostHog Code Task-Id: 8222640f-ff3b-4f81-b63a-26361e552ae6
xcodegen generate failed because project.yml pointed configFiles at the gitignored .env.xcconfig, which never exists in a fresh checkout. PostHog.xcconfig is tracked with empty defaults and optionally includes .env.xcconfig so local secrets still take effect. Generated-By: PostHog Code Task-Id: 8222640f-ff3b-4f81-b63a-26361e552ae6
Wraps two over-long fatalError messages under the 160-char line-length limit, and passes Slider's label as an explicit argument instead of a second trailing closure to satisfy multiple_closures_with_trailing_closure. No behavior change. Generated-By: PostHog Code Task-Id: 8222640f-ff3b-4f81-b63a-26361e552ae6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PostHog's setup wizard integrated analytics into this macOS SwiftUI app using the
posthog-iosSwift Package. Anonymous product events, automatic uncaught-error capture, and a starter dashboard were configured. Runtime delivery (does an event actually reach PostHog from a compiled build) was unverified by the wizard, since it ran without Xcode/XcodeGen available — this PR adds the minimal fixes needed to get an actual macOS build passing in CI (see "CI fixes" below).Changes
project.yml— declares thePostHogSwift Package dependency (posthog-iosfrom3.59.3), attaches it to theMicStatusAItarget, and mapsPostHog.xcconfigas the Debug/Release config file.MicStatusAI/App/MicStatusAIApp.swift— initializesPostHogSDK.sharedonce at app startup, readingPOSTHOG_PROJECT_TOKEN/POSTHOG_HOSTfrom the process environment orInfo.plist, and enableserrorTrackingConfig.autoCapturefor uncaught errors.MicStatusAI/Info.plist— exposesPOSTHOG_PROJECT_TOKENandPOSTHOG_HOSTas build-setting-backed keys.MicStatusAI/Models/MicrophoneStatusModel.swift— capturesmicrophone_monitoring_toggledandmicrophone_mute_toggledon successful state changes.MicStatusAI/Views/InputLevelControl.swift— capturesinput_level_adjustedwhen the user finishes dragging the input-level slider.MicStatusAI/Coordinators/HotKeyRecorderCoordinator.swift— captureshotkey_configuredwhen a new mute hotkey is recorded.MicStatusAI/Views/HotKeySettingsView.swift— captureshotkey_restoredwhen the default hotkey is restored.MicStatusAI/Views/StatusOverlaySettingsView.swift— capturesstatus_overlay_setting_changed(enabled, duration, placement, transparency) on preference changes..env.example— documents the two required keys (POSTHOG_PROJECT_TOKEN,POSTHOG_HOST)..gitignore— ignores local.envand.env.xcconfig, which hold the real token/host and are not committed.No new PostHog events, dashboards, or insights were created by this PR — everything below already exists in PostHog from the wizard's run.
CI fixes
The wizard couldn't run a real macOS build to verify its own changes, and two problems surfaced once this PR hit
macos-15CI:xcodegen generatefailed outright.project.ymlpointedconfigFilesat.env.xcconfig, which is gitignored and never exists in a fresh checkout — this would have broken every future PR touching the app, not just this one. Fix: added a trackedPostHog.xcconfigwith empty default values that#include? ".env.xcconfig"— xcodegen always finds a config file, and a local.env.xcconfig(if present) still overrides the defaults for local development, unchanged from before..swiftlint.ymlruns as a build phase) on four violations in the wizard's own instrumentation: twofatalErrormessages inMicStatusAIApp.swiftexceeded the 160-character line-length limit, and twoSlider(...)calls (InputLevelControl.swift,StatusOverlaySettingsView.swift) trippedmultiple_closures_with_trailing_closureby combiningonEditingChanged:with a trailinglabelclosure. Fix: wrapped the two long strings across multiple lines (identical text), and passedlabel:as an explicit argument instead of a trailing closure. Neither change alters behavior.Insights and dashboards created
The wizard also published a full setup report as a PostHog notebook: PostHog setup (wizard) – MicStatusAI.
How to verify
.env.xcconfig(see.env.example) with the realPOSTHOG_PROJECT_TOKEN/POSTHOG_HOST, runxcodegen generate, then build and run theMicStatusAIscheme.Environment variables (action needed before PostHog works in production)
This app has no committed production config file with real values —
PostHog.xcconfigships with empty defaults, and the real token/host live only in the gitignored local.env.xcconfig, which is never present in a CI checkout. The release pipeline (.github/workflows/release.yml, triggered onv*.*.*tags) runsxcodegen generatestraight from a clean checkout, so a tagged release build will compile, butMicStatusAIApp.swift's guard clauses will silently no-op in Release (no PostHog setup, no crash) sincePOSTHOG_PROJECT_TOKEN/POSTHOG_HOSTresolve to empty.To make production builds send data, add two repository secrets and a step to
release.yml(beforexcodegen generate) that writes a local.env.xcconfigfrom them —PostHog.xcconfig's#include?will then pick it up automatically:POSTHOG_PROJECT_TOKENphc_mcsrUeztBvNvgBZGpbPHFoyLQfH72zVmFdtEHsFf7NPJPOSTHOG_HOSThttps://eu.i.posthog.comThen add a step ahead of "Generate Xcode project" in
release.yml:Note the
${POSTHOG_HOST/\/\//\/\$()\/}substitution:.xcconfigfiles treat//as a comment start, sohttps://must be written ashttps:/$()/in that file specifically (the existing local.env.xcconfigalready uses this escape) — a plain.envfile does not need it.I did not make this change myself: it touches the release/signing pipeline and requires creating org secrets I don't have access to from here, both outside what this PR should do unattended.
Validation
xcodegen generateswiftlint lint --config .swiftlint.yml.github/workflows/pr-build.ymlonmacos-15)Created with PostHog Code