iOS product analytics installation
Contents
PostHog is available through CocoaPods or as a Swift Package Manager dependency.
Add PostHog to your Podfile: Or install via Swift Package Manager: Initialize PostHog in your AppDelegate: Once installed, PostHog will automatically start capturing events. You can also manually send events to test your integration: By default, for backwards compatibility reasons, events are sent with person profile processing enabled. This means a person profile will be created for each user who triggers an event. If you want to disable person profile processing for certain events, send the event with the following property: Check if a feature flag is enabled: For multivariate flags, check which variant the user has been assigned: Experiments run on top of our feature flags. Once you've implemented the flag in your code, you run an experiment by creating a new experiment in the PostHog dashboard.Install via CocoaPods
RequiredConfigure PostHog
RequiredSend events
RecommendedEvaluate boolean feature flags
RequiredEvaluate multivariate feature flags
OptionalRunning experiments
Optional
Swift Package Manager
Add PostHog as a dependency in your Xcode project Package Dependencies and select the project target for your app.
For Swift Package Manager projects, add PostHog to your Package.swift dependencies:
Then add it as a dependency for your target:
SwiftUI configuration
If you're using SwiftUI lifecycle, initialize PostHog in your app's init():
For more advanced options, see the configuration page.