Skip to content

feat(posthog): Add session recording support#632

Merged
robingenz merged 20 commits into
capawesome-team:mainfrom
riley-wv:feat/session-recording-and-error-tracking
Nov 12, 2025
Merged

feat(posthog): Add session recording support#632
robingenz merged 20 commits into
capawesome-team:mainfrom
riley-wv:feat/session-recording-and-error-tracking

Conversation

@riley-wv
Copy link
Copy Markdown
Contributor

@riley-wv riley-wv commented Oct 5, 2025

• 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:

  • The changes have been tested successfully.
  • A changeset has been created (npm run changeset).
  • I have read and followed the pull request guidelines.

Closes: #630

…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.
Copy link
Copy Markdown
Member

@robingenz robingenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Just a few small changes needed.

Comment thread package.json
Comment thread packages/posthog/package.json
Comment thread packages/posthog/src/definitions.ts Outdated
Comment thread packages/posthog/src/definitions.ts Outdated
Comment thread packages/posthog/src/definitions.ts Outdated
Comment thread packages/posthog/src/web.ts Outdated
Comment thread .changeset/deep-webs-film.md Outdated
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
@riley-wv
Copy link
Copy Markdown
Contributor Author

riley-wv commented Oct 7, 2025

@robingenz all request changes have been made

Comment thread package-lock.json
@riley-wv
Copy link
Copy Markdown
Contributor Author

riley-wv commented Oct 7, 2025

Okay thats all been reverted

@robingenz
Copy link
Copy Markdown
Member

@riley-wv Please fix the Android and iOS builds so that i can merge your PR.

@robingenz
Copy link
Copy Markdown
Member

@riley-wv The workflow is still failing.

@riley-wv
Copy link
Copy Markdown
Contributor Author

Saw this @robingenz. I have been busy, but will make sure to push a fix for this ASAP

@wahibimoh
Copy link
Copy Markdown

@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
@riley-wv riley-wv requested a review from robingenz October 21, 2025 02:18
@riley-wv
Copy link
Copy Markdown
Contributor Author

riley-wv commented Oct 21, 2025

@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:

  • Error tracking could only be implemented on Android
  • I had to upgrade the PostHog android version to 3.24.0 to support error tracking

@robingenz
Copy link
Copy Markdown
Member

I had to upgrade the PostHog android version to 3.24.0 to support error tracking

@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.

@riley-wv
Copy link
Copy Markdown
Contributor Author

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

@robingenz
Copy link
Copy Markdown
Member

@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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Oct 21, 2025

Open in StackBlitz

@capawesome/capacitor-age-signals

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-age-signals@632

@capawesome-team/capacitor-android-battery-optimization

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome-team/capacitor-android-battery-optimization@632

@capawesome/capacitor-android-dark-mode-support

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-android-dark-mode-support@632

@capawesome/capacitor-android-edge-to-edge-support

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-android-edge-to-edge-support@632

@capawesome-team/capacitor-android-foreground-service

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome-team/capacitor-android-foreground-service@632

@capawesome/capacitor-app-review

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-app-review@632

@capawesome/capacitor-app-shortcuts

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-app-shortcuts@632

@capawesome/capacitor-app-update

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-app-update@632

@capawesome/capacitor-asset-manager

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-asset-manager@632

@capawesome/capacitor-background-task

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-background-task@632

@capawesome/capacitor-badge

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-badge@632

@capawesome/capacitor-cloudinary

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-cloudinary@632

@capawesome-team/capacitor-datetime-picker

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome-team/capacitor-datetime-picker@632

@capawesome-team/capacitor-file-opener

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome-team/capacitor-file-opener@632

@capawesome/capacitor-file-picker

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-file-picker@632

@capawesome/capacitor-libsql

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-libsql@632

@capawesome/capacitor-live-update

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-live-update@632

@capawesome/capacitor-managed-configurations

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-managed-configurations@632

@capawesome/capacitor-photo-editor

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-photo-editor@632

@capawesome/capacitor-posthog

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-posthog@632

@capawesome/capacitor-realtimekit

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-realtimekit@632

@capawesome/capacitor-screen-orientation

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-screen-orientation@632

@capawesome/capacitor-screenshot

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-screenshot@632

@capawesome/capacitor-torch

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-torch@632

commit: 9426608

@riley-wv
Copy link
Copy Markdown
Contributor Author

Okay @robingenz. I will do that now

@riley-wv riley-wv changed the title feat(posthog): Add session recording and error tracking support feat(posthog): Add session recording support Oct 21, 2025
@riley-wv
Copy link
Copy Markdown
Contributor Author

@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?

@riley-wv
Copy link
Copy Markdown
Contributor Author

@robingenz error tracking has been moved.

Open issue - #645

Open PR - #646

Comment thread packages/posthog/src/web.ts Outdated
Comment thread packages/posthog/ios/Plugin/PosthogPlugin.swift Outdated
Comment thread packages/posthog/android/build.gradle
Comment thread .changeset/clean-apricots-happen.md Outdated
@riley-wv
Copy link
Copy Markdown
Contributor Author

Sorry @robingenz, I have gone ahead and fixed all of those issues now

Comment thread packages/posthog/android/build.gradle
Comment thread packages/posthog/src/definitions.ts Outdated
Comment thread packages/posthog/src/definitions.ts Outdated
@riley-wv
Copy link
Copy Markdown
Contributor Author

That's all done @robingenz

robingenz
robingenz previously approved these changes Oct 24, 2025
Copy link
Copy Markdown
Member

@robingenz robingenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@robingenz
Copy link
Copy Markdown
Member

@riley-wv Please fix the lint error.

@robingenz
Copy link
Copy Markdown
Member

@riley-wv Did you already had a chance to take a look at the linting issue?

@byoung96
Copy link
Copy Markdown

@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.

@riley-wv
Copy link
Copy Markdown
Contributor Author

Should all pass now @robingenz. My apologies for missing these notifications prior. I was at an offsite last week. This will now all pass

Copy link
Copy Markdown
Member

@robingenz robingenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thank you!

@robingenz robingenz merged commit 419231d into capawesome-team:main Nov 12, 2025
6 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 12, 2025
@gcarpi
Copy link
Copy Markdown

gcarpi commented Nov 17, 2025

Hi everyone, the record in PostHog isn’t displaying correctly. Do you know what might be causing this?

Screenshot 2025-11-17 at 15 33 56

@robingenz
Copy link
Copy Markdown
Member

@riley-wv Any idea?

@byoung96
Copy link
Copy Markdown

I'd mention that I was only able to get this working when screenshotMode is enabled.

@gcarpi
Copy link
Copy Markdown

gcarpi commented Nov 17, 2025

I'd mention that I was only able to get this working when screenshotMode is enabled.

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
      }
    }

@byoung96
Copy link
Copy Markdown

@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
    }
}

@gcarpi
Copy link
Copy Markdown

gcarpi commented Nov 17, 2025

@byoung96 Not working yet for me =/

Where do you put this config? On capacitor.config.ts?

@byoung96
Copy link
Copy Markdown

@gcarpi I actually forked this branch, because it was taking some time to get merged, and added a setup function to the plugin that allows me to initialize PostHog before I mount my react app.

Don't remember if I did anything so I'm not sure why yours isn't working..

@TheRealDarkCoder
Copy link
Copy Markdown

Hi everyone, the record in PostHog isn’t displaying correctly. Do you know what might be causing this?

Screenshot 2025-11-17 at 15 33 56

Having the exact same issue, android 16.

Posthog: {
      apiKey: "...",
      host: "https://us.i.posthog.com",
      enableSessionReplay: true,
      sessionReplayConfig: {
        screenshotMode: true,
        maskAllTextInputs: false,
        maskAllImages: false,
        maskAllSandboxedViews: false,
      },
    },

Should we create an issue?

@robingenz
Copy link
Copy Markdown
Member

@riley-wv Could you take another look at it? Maybe we should add some more information on how to configure/test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Session Recordings

6 participants