A/B testing enables you to test the impact of product changes and understand how they affect your users' behaviour. For example:
- How changes to your onboarding flow affect your signup rate.
- If different designs of your app's dashboard increase user engagement and retention.
- The impact a free trial period versus money-back guarantee to determine which results in more customers.
A/B tests are also referred to as "experiments", and this is how we refer to them in the PostHog app.
To start using A/B tests, install PostHog with the library you want to run tests in (if you haven't already):
PostHog is available through CocoaPods or you can add it as a Swift Package Manager based dependency.
CocoaPods
pod "PostHog", "~> 3.0.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:
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:
.target(name: "myApp",dependencies: [.product(name: "PostHog", package: "posthog-ios")]),
Configuration
import Foundationimport PostHogimport UIKitclass 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}}