Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions context/commandments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ commandments:
- If the project uses App Sandbox (macOS), add `ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES` to the target's build settings so PostHog can reach its servers — do NOT disable the sandbox entirely

ios:
- Install the PostHog iOS SDK as `PostHog` via Swift Package Manager or CocoaPods, using `https://github.com/PostHog/posthog-ios.git` for SPM
- Install the PostHog iOS SDK as `PostHog` via Swift Package Manager, using `https://github.com/PostHog/posthog-ios.git`. posthog-ios 4.x ships only through SPM and needs iOS 15 or later; CocoaPods stays on 3.x, so only keep CocoaPods for an app that already installs posthog-ios 3.x that way
- Initialize `PostHogSDK.shared.setup(config)` exactly once and as early as possible, either in `UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:)` or in the SwiftUI `App` initializer
- For SwiftUI apps, prefer meaningful `.postHogScreenView(...)` modifiers for screen tracking because automatic SwiftUI screen names can be internal view identifiers
- Call `PostHogSDK.shared.identify(...)` after login and `PostHogSDK.shared.reset()` on logout; keep PII in user properties, not event properties
Expand All @@ -299,12 +299,12 @@ commandments:
- posthog_flutter is the Flutter SDK package name; install it with `flutter pub add posthog_flutter` or add it to `pubspec.yaml`, at the version the Flutter SDK docs pin
- For manual setup, call `WidgetsFlutterBinding.ensureInitialized()`, create a `PostHogConfig`, then await `Posthog().setup(config)` before `runApp()`
- For Android, ensure `minSdkVersion` is at least `23`. If the current value is lower than `23` or missing, update/add it as `minSdkVersion 23`; if it is already `23` or higher, leave it unchanged. Configure `com.posthog.posthog.PROJECT_TOKEN` and `com.posthog.posthog.POSTHOG_HOST` in `android/app/src/main/AndroidManifest.xml` unless using manual setup with `AUTO_INIT=false`
- For iOS, ensure the minimum deployment target is at least iOS `13.0`. If the current `platform :ios` value is lower than `13.0` or missing, update/add it as `platform :ios, '13.0'`; if it is already `13.0` or higher, leave it unchanged. Configure `com.posthog.posthog.PROJECT_TOKEN` and `com.posthog.posthog.POSTHOG_HOST` in `ios/Runner/Info.plist` unless using manual setup
- For iOS, posthog_flutter 6.x installs through Swift Package Manager only, which needs Flutter 3.41 or later (run `flutter config --enable-swift-package-manager` on 3.41 to 3.43), and requires iOS 15. Ensure the minimum deployment target is at least iOS `15.0`: if the Podfile's `platform :ios` value is lower than `15.0`, update it to `platform :ios, '15.0'`, and if the Xcode project's `IPHONEOS_DEPLOYMENT_TARGET` is lower, raise it to `15.0`; leave higher values unchanged. On Flutter older than 3.41, use posthog_flutter 5.x, which supports CocoaPods and iOS 13. Configure `com.posthog.posthog.PROJECT_TOKEN` and `com.posthog.posthog.POSTHOG_HOST` in `ios/Runner/Info.plist` unless using manual setup
- For Session Replay or Surveys, disable auto-init with `com.posthog.posthog.AUTO_INIT=false` and initialize manually so the required options can be enabled
- For Flutter Web, add the posthog-js web snippet to `web/index.html`. If you are instructed to ever embed the HTML snippet into the user's code, write the real token directly into the snippet. It is not a secret, and when used as an HTML snippet, it should be written in literally. The example token phc_your_project_token_here is a placeholder for readers. It is not the shape to copy. Flutter Web session replay also requires Canvas capture in project settings
- Capture screen views by adding `PosthogObserver()` to the app's `navigatorObservers`, whatever routing package the app uses; where its routes are unnamed, name them so `$screen` is readable
- Call `Posthog().identify(...)` after login and `Posthog().reset()` on logout; keep PII in user properties, not event properties
- Use `beforeSend` to redact or drop Dart-captured events, but remember it does not intercept native session replay, lifecycle, or system properties
- Use `beforeSend` to redact or drop Dart-captured events. Natively captured events (session replay, lifecycle, native crashes) never reach it. On posthog_flutter 5.x it does not see native system properties. On 6.x it receives the full native event, including system properties like `$device_type`, and the callback must be synchronous. To change natively captured events on 6.x, use `PosthogFlutterPlugin.addBeforeSend` in Swift or Kotlin

astro:
- Always use the is:inline directive on PostHog script tags to prevent Astro from processing them and causing TypeScript errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Wire source map or debug-symbol generation and upload into your **production bui
2. `ENABLE_USER_SCRIPT_SANDBOXING = NO`.
3. A Run Script phase, ordered last, with `$(DWARF_DSYM_FOLDER_PATH)/$(DWARF_DSYM_FILE_NAME)/Contents/Resources/DWARF/$(EXECUTABLE_NAME)` in its Input Files, calling the SDK's bundled script — do not hand-roll the upload:
- SPM: `POSTHOG_INCLUDE_SOURCE=1 POSTHOG_CLI_DOTENV_FILE="${SRCROOT}/.env" "${BUILD_DIR%/Build/*}/SourcePackages/checkouts/posthog-ios/build-tools/upload-symbols.sh"`
- CocoaPods: `POSTHOG_INCLUDE_SOURCE=1 POSTHOG_CLI_DOTENV_FILE="${SRCROOT}/.env" "${PODS_ROOT}/PostHog/build-tools/upload-symbols.sh"`
- CocoaPods (posthog-ios 3.x only, because 4.x has no podspec): `POSTHOG_INCLUDE_SOURCE=1 POSTHOG_CLI_DOTENV_FILE="${SRCROOT}/.env" "${PODS_ROOT}/PostHog/build-tools/upload-symbols.sh"`
Copy the invocation verbatim — the `POSTHOG_INCLUDE_SOURCE=1` and `POSTHOG_CLI_DOTENV_FILE` prefixes HAVE to be there. This needs a recent `posthog-cli` (older ones silently ignore `POSTHOG_CLI_DOTENV_FILE`); the PostHog wizard installs it for you, so do not run `npm install -g` yourself.
- **Android (Gradle)** Android uploads **ProGuard/R8 mapping files**, not source maps. Apply the `com.posthog.android` Gradle plugin on the **app module's** `build.gradle(.kts)` (never the root project), per the reference — the plugin hooks the build and uploads automatically, do not hand-roll a `posthog-cli` step. Gotchas:
1. The plugin only hooks minified variants — if the release build type has `isMinifyEnabled = false`, set it to `true` (keep the existing `proguardFiles` line) or nothing is uploaded.
Expand All @@ -66,13 +66,13 @@ Wire source map or debug-symbol generation and upload into your **production bui
- **React Native (Expo)** Per the reference: add the `posthog-react-native/expo` plugin entry to `plugins` in `app.json`, and switch `metro.config.js` to `getPostHogExpoConfig` from `posthog-react-native/metro`. The reference badges **native crash symbolication** as *optional* — here it is not: enable `uploadNativeSymbols` with source inclusion on the plugin entry.
Gotchas:
1. The PostHog wizard installs `posthog-cli` for you — do not run `npm install -g` yourself.
2. You **must** also enable native crash autocapture (`errorTracking.autocapture.nativeCrashes`) in the SDK setup and install the `@posthog/react-native-plugin` package it depends on — per the reference.
2. You **must** also enable native crash autocapture (`errorTracking.autocapture.nativeCrashes`) in the SDK setup and install the `@posthog/react-native-plugin` package it depends on — per the reference. `@posthog/react-native-plugin` 3.x needs React Native 0.75 or later; on older React Native, install `@posthog/react-native-plugin@^2`.
- **Flutter** Wire the upload path for each platform the app ships (`web/`, `android/`, `ios/`). Dart AOT symbols and Android/iOS native crash symbols are separate uploads.
- **Web** Run `flutter build web --source-maps`, then `posthog-cli sourcemap process --directory build/web` as a post-build step.
- **Android and iOS Dart AOT** Use `posthog_flutter` 5.58.0 or later and `posthog-cli` 0.19.0 or later. Build release artifacts with `--split-debug-info`: `flutter build apk --release --split-debug-info=build/posthog-symbols/android` and `flutter build ipa --release --split-debug-info=build/posthog-symbols/ios` (on macOS). Add `--obfuscate` to the build command if the app uses obfuscation. From the Flutter project root, upload the matching `.symbols` files after each build with `posthog-cli --dotenv-file .env symbol-sets upload --directory build/posthog-symbols/android` or `--directory build/posthog-symbols/ios`. Use separate or cleaned symbol directories for each deployed build. Run this on the build machine and never rebuild the app between the upload and deployment.
- **Optional Dart source context** To show source lines as well as function names and line numbers, add `--include-source --source-root ./lib` to the Dart symbol upload command. The source root limits **uploaded source files**, not the `.symbols` files discovered in the symbol directory. Review the app's source before opting in. Without these flags, only symbols are uploaded.
- **Android Java/Kotlin crashes** Follow the **Android (Gradle)** bullet above, on `android/app/build.gradle.kts` (never `android/build.gradle.kts`). Flutter's `android/settings.gradle.kts` owns plugin versions: declare `id("com.posthog.android") version "<latest>" apply false` there, then apply it versionless in the app module. Skip that bullet's `isMinifyEnabled` step — Flutter always shrinks release builds.
- **iOS native crashes** Follow the **iOS (Xcode)** bullet above, on the **Runner** target in `ios/Runner.xcworkspace`. Flutter is always CocoaPods: `${PODS_ROOT}/PostHog/build-tools/upload-symbols.sh`.
- **iOS native crashes** Follow the **iOS (Xcode)** bullet above, on the **Runner** target in `ios/Runner.xcworkspace`. `posthog_flutter` 6.0 and later install `posthog-ios` through Swift Package Manager, so use the SPM path. `posthog_flutter` 5.x uses CocoaPods: `${PODS_ROOT}/PostHog/build-tools/upload-symbols.sh`.

Dart exceptions do not need `captureNativeExceptions`. Set `captureNativeExceptions = true` in `PostHogConfig.errorTrackingConfig` to capture native Android and iOS exceptions; it defaults to `false`. Dart AOT symbols resolve Dart frames from the same release build, but they do not restore obfuscated exception class names or add source context to ordinary Dart traces without matching AOT metadata.

Expand Down
2 changes: 1 addition & 1 deletion example-apps/android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ android {

dependencies {
// PostHog Android SDK
implementation 'com.posthog:posthog-android:3.+'
implementation 'com.posthog:posthog-android:4.+'

// Other dependencies...
}
Expand Down
2 changes: 1 addition & 1 deletion example-apps/android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ activityCompose = "1.8.0"
kotlin = "2.0.21"
composeBom = "2024.09.00"
navigationCompose = "2.7.5"
posthog = "3.72.1"
posthog = "4.0.0"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand Down
6 changes: 2 additions & 4 deletions example-apps/flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ as well — a Dart-side setup alone leaves web builds capturing nothing. See
```bash
flutter doctor
```
2. **For iOS/macOS**: a Mac with Xcode and [CocoaPods](https://guides.cocoapods.org/using/getting-started.html) (`brew install cocoapods`)
2. **For iOS/macOS**: a Mac with Xcode 26 or later. `posthog_flutter` 6 installs through Swift Package Manager, so use Flutter 3.44.2 or later (Swift Package Manager is on by default from 3.44, and this app's Dart constraint needs 3.44.2)
3. **For Android**: Android Studio with an emulator or a connected device
4. **For Web**: Chrome

Expand Down Expand Up @@ -64,8 +64,6 @@ flutter run -d chrome # Web (tok
flutter run -d macos --dart-define=POSTHOG_PROJECT_TOKEN=phc_... # macOS
```

For iOS, install pods first (first time only): `cd ios && pod install && cd ..`

## Project structure

```
Expand All @@ -89,7 +87,7 @@ test/
└── screens/ # Event capture + error tracking widget tests

android/ # AUTO_INIT disabled in AndroidManifest.xml
ios/ # AUTO_INIT disabled in Runner/Info.plist; Podfile pins iOS 13+
ios/ # AUTO_INIT disabled in Runner/Info.plist; Runner targets iOS 15+
web/ # posthog-js snippet in index.html
macos/ # AUTO_INIT disabled in Runner/Info.plist;
# network.client entitlement for the app sandbox
Expand Down
44 changes: 0 additions & 44 deletions example-apps/flutter/ios/Podfile

This file was deleted.

6 changes: 3 additions & 3 deletions example-apps/flutter/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -486,7 +486,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -537,7 +537,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
43 changes: 0 additions & 43 deletions example-apps/flutter/macos/Podfile

This file was deleted.

6 changes: 3 additions & 3 deletions example-apps/flutter/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down Expand Up @@ -553,7 +553,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -603,7 +603,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
2 changes: 1 addition & 1 deletion example-apps/flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
cupertino_icons: ^1.0.8
# PostHog Flutter SDK — the only dependency to add for PostHog integration.
# @see https://posthog.com/docs/libraries/flutter
posthog_flutter: ^5.32.1
posthog_flutter: ^6.0.0

dev_dependencies:
flutter_test:
Expand Down
4 changes: 4 additions & 0 deletions example-apps/flutter/test/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class FakePosthogPlatform extends PosthogFlutterPlatformInterface {
required String userId,
Map<String, Object>? userProperties,
Map<String, Object>? userPropertiesSetOnce,
Map<String, Object?>? options,
}) async {
callOrder.add('identify');
identifyCalls.add((
Expand All @@ -51,6 +52,7 @@ class FakePosthogPlatform extends PosthogFlutterPlatformInterface {
Map<String, Object>? properties,
Map<String, Object>? userProperties,
Map<String, Object>? userPropertiesSetOnce,
Map<String, Object?>? options,
}) async {
callOrder.add('capture');
capturedEvents.add((eventName: eventName, properties: properties));
Expand All @@ -61,6 +63,7 @@ class FakePosthogPlatform extends PosthogFlutterPlatformInterface {
required Object error,
StackTrace? stackTrace,
Map<String, Object>? properties,
Map<String, Object?>? options,
}) async {
callOrder.add('captureException');
capturedExceptions.add((
Expand All @@ -74,6 +77,7 @@ class FakePosthogPlatform extends PosthogFlutterPlatformInterface {
Future<void> screen({
required String screenName,
Map<String, Object>? properties,
Map<String, Object?>? options,
}) async {
callOrder.add('screen');
screenNames.add(screenName);
Expand Down
2 changes: 1 addition & 1 deletion example-apps/swift-xcodegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ So the PostHog SPM dependency lives in `project.yml`:
packages:
PostHog:
url: https://github.com/PostHog/posthog-ios
from: 3.64.1 # check github.com/PostHog/posthog-ios/releases for the latest
from: 4.0.0 # stay on the major the project uses

targets:
BurritoStand:
Expand Down
2 changes: 1 addition & 1 deletion example-apps/swift-xcodegen/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ options:
packages:
PostHog:
url: https://github.com/PostHog/posthog-ios
from: 3.64.1
from: 4.0.0

targets:
BurritoStand:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
repositoryURL = "https://github.com/PostHog/posthog-ios";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 3.56.0;
minimumVersion = 4.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Loading