Skip to content

[Contibution]: Disable Posthog initialization when API key is missing to prevent errors for contributors #855

@alamenai

Description

@alamenai

Hi,

In the Posthog provider, we currently have this code:

if (typeof window !== "undefined") {
  posthog.init(process.env.NEXT_PUBLIC_POSTHOG_API_KEY!, {
    api_host: "https://app.posthog.com",
    capture_pageview: true,
    session_recording: {
      maskAllInputs: false,
    },
    // Enable debug mode in development
    loaded: (posthog) => {
      if (process.env.NODE_ENV === "development") posthog.debug()
    },
  })
}

For contributors who don’t have a Posthog key (or don’t intend to add one), navigating the components page currently throws errors.

I suggest updating the code to disable Posthog initialization when the API key is not provided, to prevent these errors and improve the developer experience.

If you confirm that, I can open the pull request.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions