LimitedRound 2 is open. Get your first month free, no extra charge.Join the waitlist ›
Wire in your backend

How to add PostHog to your iOS app

TL;DR. PostHog gives an iOS app product analytics, feature flags, and session insight behind one SDK. You add the package, configure it with your public project API key and host, and capture events. AppFlight wires the connector in and keeps the project key client-side, which is how PostHog is meant to be used.

What PostHog does for an iOS app

PostHog answers questions about how people use your app. You send events like signup_completed or paywall_viewed, attach properties, and build funnels, retention charts, and trends from them. It also offers feature flags, so you can ship a feature dark and enable it for a slice of users, and experiments to compare variants. Because it is open source, you can self-host it or use PostHog Cloud. The SDK uses a write-only project key, safe to ship, that can record events but cannot read your data back.

Adding PostHog with AppFlight

In AppFlight you open the integrations panel, choose PostHog, and paste your project API key and host. AppFlight stores the project key as a client value, safe to ship in the app, and keeps any personal admin key server-side if you use the admin API. From there you can ask the AI to track key events or read a feature flag, and it generates the SwiftUI calls. Because the project key is write-only, shipping it in the binary carries no read access to your analytics.

A SwiftUI example

Configure PostHog at launch, then capture an event:

import PostHog
import SwiftUI

@main
struct MyApp: App {
    init() {
        let config = PostHogConfig(
            apiKey: "phc_YourProjectKey",
            host: "https://us.i.posthog.com"
        )
        PostHogSDK.shared.setup(config)
    }
    var body: some Scene {
        WindowGroup { ContentView() }
    }
}

struct PaywallView: View {
    var body: some View {
        Text("Go Pro")
            .onAppear {
                PostHogSDK.shared.capture("paywall_viewed",
                    properties: ["source": "onboarding"])
            }
    }
}

Alternatives

Mixpanel is the closest analytics-focused comparison and has a polished reporting UI, but it does not bundle feature flags and session work the way PostHog does. Firebase Analytics is free and tightly tied to the Google stack, though it is less flexible for custom event analysis. PostHog stands out when you want analytics, feature flags, and experiments in one open-source tool you can self-host.

FAQ

Is the PostHog project API key a secret?

No. The project API key used by the iOS SDK is a write-only public key that is safe to ship in the app. It can send events but cannot read your data. The personal API key used for the admin API is the secret one and stays server-side.

Can I self-host PostHog?

Yes. PostHog is open source and can be self-hosted, or you can use PostHog Cloud. The SDK setup is the same, you just point the host at your instance. AppFlight stores the host alongside the project key.

Does PostHog do feature flags too?

Yes. Beyond event analytics, PostHog supports feature flags and experiments, so you can roll out a feature to a percentage of users and read the flag from the SDK at runtime without an App Store update.

Sources

Build this app without opening Xcode.

AppFlight turns a plain-English prompt into a real native iOS app and ships it to the App Store. Round 2 is open: free for your first month.

Join the waitlist