iOS surveys installation

  1. Add PostHog to your app

    Required

    Using it requires PostHog's iOS SDK version >= 3.31.0, but it's recommended to always use the latest version.

    PostHog is available through CocoaPods or you can add it as a Swift Package Manager based dependency.

    CocoaPods

    Podfile
    pod "PostHog", "~> 3.0"

    Swift Package Manager

    Add PostHog as a dependency in your Xcode project "Package Dependencies" and select the project target for your app, as appropriate.

    For a Swift Package Manager based project, add PostHog as a dependency in your Package.swift file's Package dependencies section:

    Package.swift
    dependencies: [
    .package(url: "https://github.com/PostHog/posthog-ios.git", from: "3.0.0")
    ],

    and then as a dependency for the Package target utilizing PostHog:

    Package.swift
    .target(
    name: "myApp",
    dependencies: [.product(name: "PostHog", package: "posthog-ios")]),

    Configuration

    Configuration is done through the PostHogConfig object. Here's a basic configuration example to get you started.

    You can find more advanced configuration options in the configuration page.

    Swift
    import Foundation
    import PostHog
    import UIKit
    class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
    let POSTHOG_API_KEY = "<ph_project_api_key>"
    // usually 'https://us.i.posthog.com' or 'https://eu.i.posthog.com'
    let POSTHOG_HOST = "https://us.i.posthog.com"
    let config = PostHogConfig(apiKey: POSTHOG_API_KEY, host: POSTHOG_HOST)
    PostHogSDK.shared.setup(config)
    return true
    }
    }

  2. Enable surveys in your configuration

    Required

    To enable surveys in your iOS app, enable surveys in your PostHog configuration:

    Swift
    let POSTHOG_API_KEY = "<ph_project_api_key>"
    // usually 'https://us.i.posthog.com' or 'https://eu.i.posthog.com'
    let POSTHOG_HOST = "https://us.i.posthog.com"
    let config = PostHogConfig(apiKey: POSTHOG_API_KEY, host: POSTHOG_HOST)
    // Surveys require iOS 15.0 or later
    if #available(iOS 15.0, *) {
    config.surveys = true
    }
    PostHogSDK.shared.setup(config)

Supported Features

FeatureSupport
Questions
All question types
Multi-question surveys
Confirmation message
Feedback button presentation
Conditional questions
Customization / Appearance
Set colors in PostHog dashboard
Shuffle questions
PostHog branding
Delay popup after screen view
Position config❌ (always bottom sheet)
HTML content
Display conditions
Feature flag & property targeting
Screen targeting
Device type targeting
Survey wait period
Event triggers
Action triggers
Partial responses

Limitations

  • Surveys are only available on iOS
  • Surveys require iOS 15.0 or later

Community questions

Was this page useful?

Questions about this page? or post a community question.