Skip to content
Merged
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
2 changes: 1 addition & 1 deletion context/commandments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ commandments:
- Use the Svelte MCP server tools to check Svelte documentation (list-sections, get-documentation) and validate components (svelte-autofixer) — always run svelte-autofixer on new or modified .svelte files before finishing

swift:
- 'Set the PostHog project token and host directly in code when creating the `PostHogConfig` (e.g. `PostHogConfig(apiKey: "<project-token>", host: "https://us.i.posthog.com")`). The project token is a public client-side key designed to ship in the app binary, so hardcoding it is safe and is the recommended approach for iOS'
- 'Set the PostHog project token and host directly in code when creating the `PostHogConfig` (e.g. `PostHogConfig(projectToken: "<project-token>", host: "https://us.i.posthog.com")`). The project token is a public client-side key designed to ship in the app binary, so hardcoding it is safe and is the recommended approach for iOS'
- 'Do NOT depend on Xcode scheme environment variables (`ProcessInfo.processInfo.environment`) as the only source of the token: they are injected only when launching from Xcode (debug/simulator), NOT in Archive/Release builds (TestFlight, App Store). Reading them is fine as an optional override, but never force-unwrap or `fatalError` on their absence — that crashes production builds on launch. Ensure a value always ships in the binary'
- 'Before editing any Xcode project file, check for a project generator spec. If a `project.yml` with XcodeGen-shaped content (top-level `targets:` and/or `packages:` keys — do not trust the filename alone) exists at the repo root, the `.xcodeproj` is generated and MUST NOT be edited directly: the next `xcodegen generate` silently wipes any edit to `project.pbxproj`. Instead declare the package in `project.yml` under `packages:` as `PostHog: { url: https://github.com/PostHog/posthog-ios, from: <latest release> }`, add `- package: PostHog` to the app target''s `dependencies:` list, then tell the user to re-run `xcodegen generate` to apply it'
- When adding SPM dependencies to project.pbxproj (only when no XcodeGen `project.yml` generator spec exists — see the rule above), create three distinct objects with unique UUIDs — a `PBXBuildFile` (with `productRef`), an `XCSwiftPackageProductDependency` (with `package` and `productName`), and an `XCRemoteSwiftPackageReference` (with `repositoryURL` and `requirement`). The build file goes in the Frameworks phase `files`, the product dependency goes in the target's `packageProductDependencies`, and the package reference goes in the project's `packageReferences`.
Expand Down
2 changes: 1 addition & 1 deletion context/skills/integration/description-kmp-docs-only.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This skill helps you add PostHog analytics to {display_name} applications using
1. Detect the existing Kotlin Multiplatform app structure. Check `settings.gradle.kts`, the shared module's `build.gradle.kts` (look for the `kotlin("multiplatform")` plugin and a `commonMain` source set), and the per-platform entry points (Android `Application`/`Activity`, iOS `MainViewController`, web `main`).
2. Read the reference files below before changing code. They are the source of truth for SDK installation, initialization, event capture, identification, feature flags, group analytics, session replay, and error tracking.
3. Install the SDK by adding `implementation("com.posthog:posthog-kmp:<version>")` to the shared module's `commonMain` dependencies in `build.gradle.kts` — not to a platform-specific source set. Check the latest version on Maven Central (https://central.sonatype.com/artifact/com.posthog/posthog-kmp) rather than hardcoding a stale one.
4. Initialize PostHog once, early in the app lifecycle, from shared code: `PostHog.setup(config = PostHogConfig(apiKey = ..., host = ...), context = PostHogContext())`. Use environment or generated build-config values for the project token and host. Never hardcode secrets.
4. Initialize PostHog once, early in the app lifecycle, from shared code: `PostHog.setup(config = PostHogConfig(projectToken = ..., host = ...), context = PostHogContext())`. Use environment or generated build-config values for the project token and host. Never hardcode secrets.
5. Build `PostHogContext` per platform: on Android pass `PostHogContext(application)`; on iOS and web use the no-argument `PostHogContext()`. All PostHog APIs live in the `com.posthog.kmp` package.
6. Add `PostHog.identify(...)` at login/signup boundaries and `PostHog.reset()` on logout.
7. Verify with the project's normal Gradle commands, such as `./gradlew build`, or the repository's existing checks.
Expand Down
12 changes: 6 additions & 6 deletions example-apps/android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The PostHog configuration is stored in `local.properties` (this file is gitignor

```properties
# PostHog configuration
posthog.apiKey=your_posthog_project_token
posthog.projectToken=your_posthog_project_token
posthog.host=https://us.i.posthog.com
```

Expand Down Expand Up @@ -89,7 +89,7 @@ class BurritoApplication : Application() {
super.onCreate()

val posthogConfig = PostHogConfig(
apiKey = BuildConfig.POSTHOG_PROJECT_TOKEN,
projectToken = BuildConfig.POSTHOG_PROJECT_TOKEN,
host = BuildConfig.POSTHOG_HOST
).apply {
// Enable session replay
Expand Down Expand Up @@ -185,7 +185,7 @@ PostHog automatically captures uncaught exceptions when configured:

```kotlin
val posthogConfig = PostHogConfig(
apiKey = BuildConfig.POSTHOG_PROJECT_TOKEN,
projectToken = BuildConfig.POSTHOG_PROJECT_TOKEN,
host = BuildConfig.POSTHOG_HOST
).apply {
// Automatic exception capture is enabled by default
Expand Down Expand Up @@ -229,7 +229,7 @@ Session replay is enabled in the PostHog configuration:

```kotlin
val posthogConfig = PostHogConfig(
apiKey = BuildConfig.POSTHOG_PROJECT_TOKEN,
projectToken = BuildConfig.POSTHOG_PROJECT_TOKEN,
host = BuildConfig.POSTHOG_HOST
).apply {
sessionReplay = true
Expand Down Expand Up @@ -259,7 +259,7 @@ The instance is available throughout your application after initialization.
android {
defaultConfig {
// PostHog configuration
buildConfigField "String", "POSTHOG_PROJECT_TOKEN", "\"${project.findProperty("posthog.apiKey") ?: ""}\""
buildConfigField "String", "POSTHOG_PROJECT_TOKEN", "\"${project.findProperty("posthog.projectToken") ?: ""}\""
buildConfigField "String", "POSTHOG_HOST", "\"${project.findProperty("posthog.host") ?: "https://us.i.posthog.com"}\""
}
}
Expand All @@ -282,7 +282,7 @@ localProperties.load(new FileInputStream(rootProject.file("local.properties")))

android {
defaultConfig {
buildConfigField "String", "POSTHOG_PROJECT_TOKEN", "\"${localProperties.getProperty("posthog.apiKey", "")}\""
buildConfigField "String", "POSTHOG_PROJECT_TOKEN", "\"${localProperties.getProperty("posthog.projectToken", "")}\""
buildConfigField "String", "POSTHOG_HOST", "\"${localProperties.getProperty("posthog.host", "https://us.i.posthog.com")}\""
}
}
Expand Down
2 changes: 1 addition & 1 deletion example-apps/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ android {
buildConfigField(
"String",
"POSTHOG_PROJECT_TOKEN",
"\"${localProperties.getProperty("posthog.apiKey", "")}\""
"\"${localProperties.getProperty("posthog.projectToken", "")}\""
)
buildConfigField(
"String",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BurritoApplication : Application() {

// Initialize PostHog early in Application lifecycle
val config = PostHogAndroidConfig(
apiKey = BuildConfig.POSTHOG_PROJECT_TOKEN,
projectToken = BuildConfig.POSTHOG_PROJECT_TOKEN,
host = BuildConfig.POSTHOG_HOST,
).apply {
debug = true
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.31.0"
posthog = "3.72.1"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand Down
2 changes: 1 addition & 1 deletion example-apps/android/local.properties.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
sdk.dir=/path/to/your/android/sdk

# PostHog configuration
posthog.apiKey=your_posthog_project_token_here
posthog.projectToken=your_posthog_project_token_here
posthog.host=https://us.i.posthog.com
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private let posthogHost = "https://us.i.posthog.com"
@main
struct BurritoStandApp: App {
init() {
let config = PostHogConfig(apiKey: posthogProjectToken, host: posthogHost)
let config = PostHogConfig(projectToken: posthogProjectToken, host: posthogHost)
config.captureApplicationLifecycleEvents = true
config.debug = true
PostHogSDK.shared.setup(config)
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 @@ -82,7 +82,7 @@ target's `dependencies:` — never in the pbxproj. See the snippet above.
```swift
import PostHog

let config = PostHogConfig(apiKey: "<your-project-token>", host: "https://us.i.posthog.com")
let config = PostHogConfig(projectToken: "<your-project-token>", host: "https://us.i.posthog.com")
config.captureApplicationLifecycleEvents = true
PostHogSDK.shared.setup(config)
```
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.0.0;
minimumVersion = 3.56.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct BurritoConsiderationClientApp: App {
@State private var userState = UserState()

init() {
let config = PostHogConfig(apiKey: posthogProjectToken, host: posthogHost)
let config = PostHogConfig(projectToken: posthogProjectToken, host: posthogHost)
config.captureApplicationLifecycleEvents = true
config.debug = true
PostHogSDK.shared.setup(config)
Expand Down
2 changes: 1 addition & 1 deletion example-apps/swift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import PostHog

// The project token is a public client-side key, so it's safe to ship in the
// binary. Replace the placeholder with your token from the PostHog project settings.
let config = PostHogConfig(apiKey: "<your-project-token>", host: "https://us.i.posthog.com")
let config = PostHogConfig(projectToken: "<your-project-token>", host: "https://us.i.posthog.com")
config.captureApplicationLifecycleEvents = true
PostHogSDK.shared.setup(config)
```
Expand Down
Loading