feat(nuxt): add enabled option in module config#3057
feat(nuxt): add enabled option in module config#3057robinsimonklein wants to merge 3 commits intoPostHog:mainfrom
Conversation
|
@robinsimonklein is attempting to deploy a commit to the PostHog Team on Vercel. A member of the Team first needs to authorize it. |
|
@robinsimonklein - thanks for the contribution. It makes sense to add an option to disable it. I just think that making posthog I've checked and:
I'm happy to merge this once we solve this :) |
|
@ablaszkiewicz Good catch on the For the browser SDK, I suspect My initial thinking was that optional chaining ( |
|
I think a good solution would be to use this suggested posthogConfig: {
publicKey: env.posthogApiKey,
host: env.posthogApiHost,
clientConfig: {
autocapture: env.posthogEnabled,
capture_exceptions: env.posthogAutocaptureExceptions,
loaded: function (ph) {
if (!env.posthogEnabled) {
ph.opt_out_capturing();
ph.set_config({ disable_session_recording: true });
}
},
},
sourcemaps: {
enabled: env.posthogAutocaptureExceptions,
envId: env.posthogProjectId,
personalApiKey: env.posthogPersonalApiKey,
},
}It's not the same as skipping posthog initialization but I think it is better DX compared to using optional chaining if the composable returns |
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
|
This PR was closed due to lack of activity. Feel free to reopen if it's still relevant. |
Problem
Developers using the Nuxt module often need to disable PostHog in certain environments (testing, local development, staging). Currently, the only way to do this is to conditionally exclude the module from
nuxt.config.ts, which can lead to runtime errors if code tries to use PostHog composables when the module isn't loaded.Changes
Added an optional
enabledconfiguration option to the Nuxt moduleBehavior
Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file