PostHog provides native mobile SDKs for iOS, Android, React Native, and Flutter with full support for event tracking, feature flags, session replay, and user identification.
iOS Native Swift/Objective-C SDK
Android Native Kotlin/Java SDK
React Native Cross-platform React Native SDK
Flutter Dart-based Flutter SDK
iOS Integration
CocoaPods
Swift Package Manager
Add PostHog to your Podfile: Then run: In Xcode, go to File > Add Packages and add: https://github.com/PostHog/posthog-ios.git
Or add to your Package.swift: dependencies : [
. package (
url : "https://github.com/PostHog/posthog-ios.git" ,
from : "3.0.0"
)
]
Initialize PostHog in your AppDelegate: 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_token>"
let POSTHOG_HOST = "<ph_client_api_host>"
let config = PostHogConfig ( apiKey : POSTHOG_API_KEY, host : POSTHOG_HOST)
PostHogSDK. shared . setup (config)
return true
}
}
Capture Events PostHogSDK. shared . capture (
"button_clicked" ,
properties : [
"button_name" : "signup" ,
"screen" : "home"
]
)
Identify Users PostHogSDK. shared . identify (
"user_123" ,
userProperties : [
"email" : "[email protected] " ,
"plan" : "premium"
]
)
Feature Flags if PostHogSDK.shared. isFeatureEnabled ( "new-feature" ) {
// Show new feature
} else {
// Show old feature
}
// Get variant
let variant = PostHogSDK. shared . getFeatureFlag ( "experiment-name" )
Reset on Logout PostHogSDK. shared . reset ()
Android Integration
Add PostHog to your build.gradle dependencies: dependencies {
implementation ( "com.posthog:posthog-android:3.+" )
}
Initialize PostHog in your Application class: import android.app.Application
import com.posthog.PostHog
import com.posthog.android.PostHogAndroid
import com.posthog.android.PostHogAndroidConfig
class SampleApp : Application () {
companion object {
const val POSTHOG_API_KEY = "<ph_project_token>"
const val POSTHOG_HOST = "<ph_client_api_host>"
}
override fun onCreate () {
super . onCreate ()
val config = PostHogAndroidConfig (
apiKey = POSTHOG_API_KEY,
host = POSTHOG_HOST
)
PostHogAndroid. setup ( this , config)
}
}
Register your Application class in AndroidManifest.xml: < application
android:name = ".SampleApp"
... >
</ application >
Capture Events import com.posthog.PostHog
PostHog. capture (
event = "button_clicked" ,
properties = mapOf (
"button_name" to "signup" ,
"screen" to "home"
)
)
Identify Users PostHog. identify (
distinctId = "user_123" ,
userProperties = mapOf (
"email" to "[email protected] " ,
"plan" to "premium"
)
)
Feature Flags if (PostHog. isFeatureEnabled ( "new-feature" )) {
// Show new feature
} else {
// Show old feature
}
// Get variant
val variant = PostHog. getFeatureFlag ( "experiment-name" )
Reset on Logout
React Native Integration
npx expo install posthog-react-native expo-file-system expo-application expo-device expo-localization
npm install posthog-react-native @react-native-async-storage/async-storage react-native-device-info react-native-localize
# For iOS
cd ios && pod install
Wrap your app with the PostHogProvider: import { PostHogProvider } from 'posthog-react-native'
export function App () {
return (
< PostHogProvider
apiKey = "<ph_project_token>"
options = { {
host: "<ph_client_api_host>" ,
} }
>
< RestOfApp />
</ PostHogProvider >
)
}
Use the Hook import { usePostHog } from 'posthog-react-native'
function MyComponent () {
const posthog = usePostHog ()
const handlePress = () => {
posthog . capture ( 'button_pressed' , {
button_name: 'signup'
})
}
return < Button onPress = { handlePress } title = "Sign Up" />
}
Identify Users const posthog = usePostHog ()
posthog . identify ( 'user_123' , {
email: '[email protected] ' ,
name: 'Jane Doe'
})
Feature Flags import { useFeatureFlag } from 'posthog-react-native'
function FeatureComponent () {
const showNewUI = useFeatureFlag ( 'new-ui' )
if ( showNewUI ) {
return < NewUI />
}
return < OldUI />
}
Flutter Integration
Installation
Platform Setup
Usage
Add to your pubspec.yaml: dependencies :
posthog_flutter : ^5.0.0
Then run: Add to AndroidManifest.xml: android/app/src/main/AndroidManifest.xml
< application >
< activity >
[...]
</ activity >
< meta-data
android:name = "com.posthog.posthog.API_KEY"
android:value = "<ph_project_token>"
/>
< meta-data
android:name = "com.posthog.posthog.POSTHOG_HOST"
android:value = "<ph_client_api_host>"
/>
< meta-data
android:name = "com.posthog.posthog.TRACK_APPLICATION_LIFECYCLE_EVENTS"
android:value = "true"
/>
</ application >
Update minimum SDK version in build.gradle: defaultConfig {
minSdkVersion 21
// rest of config
}
Add to Info.plist: < dict >
[...]
< key > com.posthog.posthog.API_KEY </ key >
< string >< ph_project_token ></ string >
< key > com.posthog.posthog.POSTHOG_HOST </ key >
< string >< ph_client_api_host ></ string >
< key > com.posthog.posthog.CAPTURE_APPLICATION_LIFECYCLE_EVENTS </ key >
< true />
</ dict >
Update minimum iOS version in Podfile: Capture Events import 'package:posthog_flutter/posthog_flutter.dart' ;
await Posthog (). capture (
eventName : 'button_clicked' ,
properties : {
'button_name' : 'signup' ,
'screen' : 'home'
}
);
Identify Users await Posthog (). identify (
userId : 'user_123' ,
userProperties : {
'email' : '[email protected] ' ,
'plan' : 'premium'
}
);
Feature Flags final isEnabled = await Posthog (). isFeatureEnabled ( 'new-feature' );
if (isEnabled) {
// Show new feature
} else {
// Show old feature
}
// Get variant
final variant = await Posthog (). getFeatureFlag ( 'experiment-name' );
Screen Tracking await Posthog (). screen (
screenName : 'HomeScreen' ,
properties : {
'category' : 'main'
}
);
Common Features
All mobile SDKs support these core features:
Automatic Event Capture
App lifecycle events (app opened, backgrounded)
Screen views (automatically tracked)
App crashes and errors
Session Replay
Mobile session replay captures screen recordings, touch interactions, and network activity (where supported).
Mobile session replay is currently in beta. Check the session replay docs for platform availability.
Group Analytics
Track events for organizations or teams:
iOS
Android
React Native
Flutter
PostHogSDK. shared . group (
type : "company" ,
key : "company_id_123" ,
groupProperties : [
"name" : "Acme Corporation" ,
"plan" : "enterprise"
]
)
Privacy & Compliance
Opt Out
All SDKs support opt-out for privacy compliance:
iOS
Android
React Native
Flutter
PostHogSDK. shared . optOut ()
PostHogSDK. shared . optIn () // Re-enable
Data Masking
Configure what data is captured:
let config = PostHogConfig ( apiKey : apiKey, host : host)
config. captureScreenViews = false
config. captureElementInteractions = false
Debugging
Enable debug mode to see SDK activity:
let config = PostHogConfig ( apiKey : apiKey, host : host)
config. debug = true
Best Practices
Initialize Early : Initialize PostHog as early as possible in your app lifecycle to ensure all events are captured.
Test on Real Devices : Always test on physical devices, not just simulators/emulators, to catch platform-specific issues.
Handle Permissions : Some features (like session replay) may require specific permissions. Handle these gracefully in your app.
Flush on Background : Events are automatically flushed when the app goes to background, but you can manually flush if needed.
iOS SDK Complete iOS SDK documentation
Android SDK Complete Android SDK documentation
React Native SDK Complete React Native documentation
Flutter SDK Complete Flutter SDK documentation
Next Steps
Feature Flags Learn about mobile feature flag patterns
Session Replay Configure mobile session replay
Group Analytics Track B2B metrics by organization
SDK Overview Explore all available SDKs