A/B testing installation

Last updated:

|Edit this page|

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

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

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
}
}

Questions? Ask Max AI.

It's easier than reading through 669 pages of documentation

Community questions

Was this page useful?

Next article

Creating an experiment

To create a new experiment, go to the A/B testing tab in the PostHog app, and click on the New experiment button in the top right. This presents you with a form where you can complete the details of your new experiment: Here's a breakdown of each field in the form: Feature flag key Each experiment is backed by a feature flag . In your code, you use this feature flag key to check which experiment variant the user has been assigned to. You can use an existing feature flag if it has multiple…

Read next article

PostHog.com doesn't use third party cookies - only a single in-house cookie.

No data is sent to a third party.

Ursula von der Leyen, President of the European Commission