Skip to content

feat(posthog): add generic configuration support to setup method#611

Closed
dwolfand wants to merge 2 commits into
capawesome-team:mainfrom
dwolfand:main
Closed

feat(posthog): add generic configuration support to setup method#611
dwolfand wants to merge 2 commits into
capawesome-team:mainfrom
dwolfand:main

Conversation

@dwolfand
Copy link
Copy Markdown

@dwolfand dwolfand commented Sep 13, 2025

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.

Overview

Adds optional config parameter to the PostHog plugin's setup() method, enabling developers to pass custom PostHog SDK configuration options during initialization.

Closes #610

Changes

  • Added optional config?: Record<string, any> parameter to SetupOptions interface
  • Web: Merge config with existing options in posthog.init()
  • Android: Use reflection to apply config properties to PostHogAndroidConfig
  • iOS: Use Key-Value Coding to apply config properties to PostHogConfig
  • Updated documentation with usage examples
  • Updated posthog-js dependency from 1.160.3 to 1.265.1

Usage Example

await Posthog.setup({
  apiKey: 'YOUR_API_KEY',
  host: 'https://eu.i.posthog.com',
  config: {
    autocapture: false,
    enable_recording_console_log: true
  },
});

Testing

  • ✅ Backward compatibility maintained - existing code works unchanged
  • ✅ Cross-platform support verified
  • ✅ Graceful error handling for invalid config properties
  • ✅ No linting errors

This enhancement provides developers with the flexibility to customize any PostHog SDK configuration option while maintaining full backward compatibility.

@robingenz
Copy link
Copy Markdown
Member

Please restore the pull request template and fill it out.

@dwolfand
Copy link
Copy Markdown
Author

Please restore the pull request template and fill it out.

Sorry about that, just updated it.

* Additional configuration options to pass to PostHog initialization.
* These will be merged with the default configuration.
*
* @since 8.0.0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* @since 8.0.0
* @since 7.3.0

const config = {
api_host: host,
});
...(options.config || {}),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Move this line one up so that i cannot overwrite api_host.

"peerDependencies": {
"@capacitor/core": ">=7.0.0",
"posthog-js": "^1.160.3"
"posthog-js": "^1.265.1"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revert this change. Otherwise, we cannot merge it before the next major release since this would be a breaking change.

"@ionic/swiftlint-config": "2.0.0",
"eslint": "8.57.0",
"posthog-js": "1.160.3",
"posthog-js": "1.265.1",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revert this change. Otherwise, we cannot merge it before the next major release since this would be a breaking change.

* @since 8.0.0
* @example { 'autocapture': false, 'enable_recording_console_log': true }
*/
config?: Record<string, any>;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Move this property before host -> alphabetical order

@@ -0,0 +1,5 @@
---
'@capawesome/capacitor-posthog': patch
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
'@capawesome/capacitor-posthog': patch
'@capawesome/capacitor-posthog': minor

'@capawesome/capacitor-posthog': patch
---

**feat: add generic configuration support to setup method**: Added optional `config` parameter to `SetupOptions` interface allowing developers to pass custom PostHog SDK configuration options during initialization. This enables fine-grained control over PostHog behavior such as `autocapture`, `enable_recording_console_log`, and other SDK-specific settings across all platforms (Web, Android, iOS).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
**feat: add generic configuration support to setup method**: Added optional `config` parameter to `SetupOptions` interface allowing developers to pass custom PostHog SDK configuration options during initialization. This enables fine-grained control over PostHog behavior such as `autocapture`, `enable_recording_console_log`, and other SDK-specific settings across all platforms (Web, Android, iOS).
feat: add `config` option to `SetupOptions`

@mirsella
Copy link
Copy Markdown
Contributor

if anyone needs this until its merged, I've rebased this PR onto main + did a release https://github.com/mirsella/capacitor-plugins/tree/posthog-config

@mirsella mirsella mentioned this pull request Dec 10, 2025
46 tasks
@robingenz
Copy link
Copy Markdown
Member

Closing due to inactivity

@robingenz robingenz closed this Mar 1, 2026
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: Add generic configuration support to setup method for PostHog

3 participants