Skip to content

Add disable prop to PostHogProvider #3217

@cjoecker

Description

@cjoecker

Is your feature request related to a problem?

Is common to disable Posthog for non-production environments.
Right now, it needs to be done like this in React:

function PostHogProviderInProd({ children }: { children: ReactNode }) {
	if (!IS_PRODUCTION) {
		return children;
	}
	return (
		<PostHogProvider
			apiKey=""
		>
			{children}
		</PostHogProvider>
	);
}

Describe the solution you'd like

It will be a better DX to disable PostHog like this:

function MyComponent({ children }: { children: ReactNode }) {
	return (
		<PostHogProvider
			apiKey=""
			disable={!IS_PRODUCTION}
		>
			{children}
		</PostHogProvider>
	);
}

A disable property should be in all posthog libraries since this is a common case.

Describe alternatives you've considered

Related sub-libraries

  • All of them
  • posthog-js (web)
  • posthog-js-lite (web lite)
  • posthog-node
  • posthog-react-native
  • @posthog/react
  • @posthog/ai
  • @posthog/convex
  • @posthog/nextjs-config
  • @posthog/nuxt
  • @posthog/rollup-plugin
  • @posthog/webpack-plugin

Additional context

Thank you for your feature request – we love each and every one!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeaturequestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions