feat(posthog): Add session recording support#632
Conversation
…lugin Implemented comprehensive session replay and error tracking capabilities across iOS, Android, and Web platforms for the PostHog Capacitor plugin. **Key Changes:** - Added `captureException()` method to capture and track errors with optional properties - Added `startSessionRecording()` and `stopSessionRecording()` methods with configurable sampling and linked flag options - Updated TypeScript definitions with new interfaces: `CaptureExceptionOptions` and `StartSessionRecordingOptions` - Extended Capacitor configuration interface with session replay and error tracking options - Implemented platform-specific option classes for iOS (Swift) and Android (Java) - Updated configuration handling to automatically enable features based on plugin config - Enhanced web implementation using posthog-js session recording and exception capture APIs - Added iOS implementation using PostHog iOS SDK methods - Added Android implementation using PostHog Android SDK methods **Configuration Options Added:** - `enableSessionReplay`: Auto-enable session recording on app start - `sessionReplaySampling`: Set sampling rate (0.0 to 1.0, default 1.0) - `sessionReplayLinkedFlag`: Enable linked flags for session recording - `enableErrorTracking`: Auto-enable error tracking These changes provide a unified, cross-platform API for session replay and error tracking while maintaining backward compatibility.
robingenz
left a comment
There was a problem hiding this comment.
Thank you! Just a few small changes needed.
Commit includes: - Revert changes to root package.json and posthog package.json - Sort definitions correctly - Update version in definitions - Remove undefined type - Remove capacitor config from web package
|
@robingenz all request changes have been made |
|
Okay thats all been reverted |
|
@riley-wv Please fix the Android and iOS builds so that i can merge your PR. |
|
@riley-wv The workflow is still failing. |
|
Saw this @robingenz. I have been busy, but will make sure to push a fix for this ASAP |
|
@riley-wv many thanks for making this contribution, I cannot wait to start using it. |
This commit includes the following: - Remove error tracking from iOS (unsupported) - Fix session replays for android and iOS
|
@robingenz, I have gone ahead and tested everything end to end and it is all compiling as expected now. I apologise for before. It seems I had tried to implement methods that did not exist. Few notes on this now:
|
@riley-wv This is considered a major change. Therefore, I need to wait to merge this PR until the next major update is released, which will be with the release of Capacitor 8. |
|
Okay @robingenz. I completely understand. I can rollback my error tracking changes and just implement session replay if that will make it a minor a change? I was under the impression because no breaking changes were made, it would be considered a minor change |
|
@riley-wv Yes, if you revert that change, we can merge it. But it would still be nice to have this feature. So I would appreciate it if you could just move the error tracking changes into another PR. |
@capawesome/capacitor-age-signals
@capawesome-team/capacitor-android-battery-optimization
@capawesome/capacitor-android-dark-mode-support
@capawesome/capacitor-android-edge-to-edge-support
@capawesome-team/capacitor-android-foreground-service
@capawesome/capacitor-app-review
@capawesome/capacitor-app-shortcuts
@capawesome/capacitor-app-update
@capawesome/capacitor-asset-manager
@capawesome/capacitor-background-task
@capawesome/capacitor-badge
@capawesome/capacitor-cloudinary
@capawesome-team/capacitor-datetime-picker
@capawesome-team/capacitor-file-opener
@capawesome/capacitor-file-picker
@capawesome/capacitor-libsql
@capawesome/capacitor-live-update
@capawesome/capacitor-managed-configurations
@capawesome/capacitor-photo-editor
@capawesome/capacitor-posthog
@capawesome/capacitor-realtimekit
@capawesome/capacitor-screen-orientation
@capawesome/capacitor-screenshot
@capawesome/capacitor-torch
commit: |
|
Okay @robingenz. I will do that now |
|
@robingenz that is removed now and will update the existing issue and open a new one for error tracking. Could you please assign the new issue to me once its created so I can open a PR? |
|
@robingenz error tracking has been moved. Open issue - #645 Open PR - #646 |
|
Sorry @robingenz, I have gone ahead and fixed all of those issues now |
|
That's all done @robingenz |
|
@riley-wv Please fix the lint error. |
|
@riley-wv Did you already had a chance to take a look at the linting issue? |
|
@robingenz My team is looking to get session recording into our Capacitor app. I'd be happy to fix the lint issue that we can get this merged. |
|
Should all pass now @robingenz. My apologies for missing these notifications prior. I was at an offsite last week. This will now all pass |
|
@riley-wv Any idea? |
|
I'd mention that I was only able to get this working when |
Thanks, but still the same for me. My configuration: Posthog: {
apiKey: 'MY_API_KEY_HERE',
host: 'https://us.i.posthog.com',
enableSessionReplay: true,
sessionReplayConfig: {
screenshotMode: true
}
} |
|
@gcarpi interesting... below is my full config {
apiKey: import.meta.env.VITE_PUBLIC_POSTHOG_KEY,
host: import.meta.env.VITE_PUBLIC_POSTHOG_HOST,
enableSessionReplay: true,
sessionReplayConfig: {
screenshotMode: true,
maskAllTextInputs: false,
maskAllImages: false,
maskAllSandboxedViews: false
}
} |
|
@byoung96 Not working yet for me =/ Where do you put this config? On |
|
@gcarpi I actually forked this branch, because it was taking some time to get merged, and added a Don't remember if I did anything so I'm not sure why yours isn't working.. |
|
@riley-wv Could you take another look at it? Maybe we should add some more information on how to configure/test it. |


• Add session recording functionality
• Add session recording start/stop methods
• Add configuration options for enableSessionReplay, sessionReplayOptions
• Implement native Android support using PostHog Android SDK
• Implement native iOS support using PostHog iOS SDK
• Add Web platform support with automatic configuration checks
• Update documentation with new API methods and configuration options
• Maintain backward compatibility with existing implementations
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run changeset).Closes: #630