You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
React Native SDK users had to explicitly enable captureAppLifecycleEvents to capture app lifecycle events (Application Installed, Application Updated, Application Opened, etc.). This is a common and expected behavior that most users want enabled. Additionally, many configuration options across the SDK lacked @default JSDoc annotations, making it harder for developers to understand the default behavior without reading source code.
Changes
captureAppLifecycleEvents now defaults to true: Both when using new PostHog() directly and via PostHogProvider. Users can disable it by setting captureAppLifecycleEvents: false.
Added @default JSDoc tags to all configuration options that have default values:
Core behavior change: captureAppLifecycleEvents now defaults to true via !== false guard; missing inline comment and test coverage for the new default.
packages/react-native/src/PostHogProvider.tsx
Provider logic updated from !captureNone && captureAll to !captureNone, correctly enabling lifecycle events by default unless autocapture is explicitly disabled.
packages/react-native/src/types.ts
JSDoc-only changes: @default tags added to PostHogAutocaptureOptions and PostHogSessionReplayConfig fields; no logic changes.
packages/core/src/types.ts
JSDoc-only changes: @default tags added to all PostHogCoreOptions fields; no logic changes.
.changeset/warm-foxes-wave.md
Correctly documents the breaking default change as a minor semver bump with clear opt-out instructions.
Comments Outside Diff (1)
packages/react-native/src/posthog-rn.ts, line 214-227 (link)
No test for the new opt-out default behavior
All existing captureAppLifecycleEvents tests in this describe block still explicitly pass captureAppLifecycleEvents: true. The core behavior this PR introduces — that calling new PostHog('key', { customStorage: mockStorage })without specifying captureAppLifecycleEvents now fires lifecycle events by default — is never exercised by the test suite.
Without a test for the new default, a future refactor could silently revert this back to opt-in without any failing tests. Consider adding a test like:
it('should capture lifecycle events by default (without setting captureAppLifecycleEvents)',async()=>{constonCapture=jest.fn()posthog=newPostHog('1',{customStorage: mockStorage,// no captureAppLifecycleEvents set — should default to truecustomAppProperties: {$app_build: '1',$app_version: '1.0.0'},})posthog.on('capture',onCapture)awaitwaitForExpect(200,()=>{expect(onCapture).toHaveBeenCalledWith(expect.objectContaining({event: 'Application Installed'}),expect.anything())})})
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/react-native/src/posthog-rn.ts
Line: 214-227
Comment:
**No test for the new opt-out default behavior**
All existing `captureAppLifecycleEvents` tests in this describe block still explicitly pass `captureAppLifecycleEvents: true`. The core behavior this PR introduces — that calling `new PostHog('key', { customStorage: mockStorage })`**without** specifying `captureAppLifecycleEvents` now fires lifecycle events by default — is never exercised by the test suite.
Without a test for the new default, a future refactor could silently revert this back to opt-in without any failing tests. Consider adding a test like:
```tsit('should capture lifecycle events by default (without setting captureAppLifecycleEvents)', async () => {
const onCapture =jest.fn()
posthog=newPostHog('1', {
customStorage: mockStorage,
// no captureAppLifecycleEvents set — should default to true
customAppProperties: { $app_build: '1', $app_version: '1.0.0' },
})
posthog.on('capture', onCapture)
awaitwaitForExpect(200, () => {
expect(onCapture).toHaveBeenCalledWith(
expect.objectContaining({ event: 'Application Installed' }),
expect.anything()
)
})
})
```
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: packages/react-native/src/posthog-rn.ts
Line: 277
Comment:
**Missing inline comment for behavior-changing condition**
This condition was changed from `if (options?.captureAppLifecycleEvents)` to `if (options?.captureAppLifecycleEvents !== false)`, flipping the default from opt-in to opt-out. Per the repository's convention, significant behavior changes like this should have an inline comment explaining the intent so future readers understand why the inverted condition is used rather than a simpler `if (options?.captureAppLifecycleEvents)` check.
```suggestion // captureAppLifecycleEvents defaults to true; only skip if explicitly set to false if (options?.captureAppLifecycleEvents !== false) {```**Rule Used:** Add inline comments to clarify the purpose of sign... ([source](https://app.greptile.com/review/custom-context?memory=4d5b48c5-045d-4693-9cd9-4081bb19508b))
**Learnt From**[PostHog/posthog#32083](https://github.com/PostHog/posthog/pull/32083)
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: packages/react-native/src/posthog-rn.ts
Line: 214-227
Comment:
**No test for the new opt-out default behavior**
All existing `captureAppLifecycleEvents` tests in this describe block still explicitly pass `captureAppLifecycleEvents: true`. The core behavior this PR introduces — that calling `new PostHog('key', { customStorage: mockStorage })`**without** specifying `captureAppLifecycleEvents` now fires lifecycle events by default — is never exercised by the test suite.
Without a test for the new default, a future refactor could silently revert this back to opt-in without any failing tests. Consider adding a test like:
```tsit('should capture lifecycle events by default (without setting captureAppLifecycleEvents)', async () => {
const onCapture =jest.fn()
posthog=newPostHog('1', {
customStorage: mockStorage,
// no captureAppLifecycleEvents set — should default to true
customAppProperties: { $app_build: '1', $app_version: '1.0.0' },
})
posthog.on('capture', onCapture)
awaitwaitForExpect(200, () => {
expect(onCapture).toHaveBeenCalledWith(
expect.objectContaining({ event: 'Application Installed' }),
expect.anything()
)
})
})
```
How can I resolve this? If you propose a fix, please make it concise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
follow up PostHog/posthog-flutter#347
React Native SDK users had to explicitly enable
captureAppLifecycleEventsto capture app lifecycle events (Application Installed, Application Updated, Application Opened, etc.). This is a common and expected behavior that most users want enabled. Additionally, many configuration options across the SDK lacked@defaultJSDoc annotations, making it harder for developers to understand the default behavior without reading source code.Changes
captureAppLifecycleEventsnow defaults totrue: Both when usingnew PostHog()directly and viaPostHogProvider. Users can disable it by settingcaptureAppLifecycleEvents: false.@defaultJSDoc tags to all configuration options that have default values:PostHogCoreOptions(core/src/types.ts):host,flushAt,flushInterval,maxBatchSize,maxQueueSize,disabled,defaultOptIn,sendFeatureFlagEvent,preloadFeatureFlags,disableRemoteConfig,disableSurveys,fetchRetryCount,fetchRetryDelay,requestTimeout,featureFlagsRequestTimeoutMs,remoteConfigRequestTimeoutMs,sessionExpirationTimeSeconds,disableCompression,disableGeoip,historicalMigrationPostHogOptions(react-native):persistence,captureAppLifecycleEvents,enableSessionReplay,enablePersistSessionIdAcrossRestartPostHogAutocaptureOptions:captureTouches,customLabelProp,noCaptureProp,maxElementsCaptured,ignoreLabels,propsToCapturePostHogSessionReplayConfig:maskAllTextInputs,maskAllImages,maskAllSandboxedViews,captureLog,iOSdebouncerDelayMs,androidDebouncerDelayMs,throttleDelayMs,captureNetworkTelemetryPostHogProviderProps:debug,autocapture(documented default behavior)Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file