Skip to content

fix: use posthog-js directly in the Gatsby example - #520

Merged
edwinyjlim merged 2 commits into
mainfrom
posthog/gatsby-use-posthog-js
Nov 13, 2026
Merged

edwinyjlim merged 2 commits into
mainfrom
posthog/gatsby-use-posthog-js

Conversation

@sarahxsanders

@sarahxsanders sarahxsanders commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Why

gatsby-plugin-posthog is deprecated and gets no more releases, so the Gatsby example (and the skills that use it) must not recommend it.

Changes

  • Remove gatsby-plugin-posthog and add posthog-js.
  • Initialize PostHog in gatsby-browser.ts (onClientEntry) with capture_pageview: "history_change", so the SDK captures pageviews on Gatsby route changes. No manual $pageview is necessary.
  • Import posthog from posthog-js in the page instead of window.posthog, and remove the window.posthog type file.
  • Update the README to match the manual JavaScript SDK setup in docs: add manual JavaScript SDK setup for Gatsby posthog.com#22305, with migration steps from the plugin.

Checked with pnpm typecheck and pnpm build (the token is inlined into the client bundle).


Created with PostHog from a Slack thread

🤖 Generated with Claude Code

gatsby-plugin-posthog is deprecated. Initialize posthog-js in gatsby-browser.ts onClientEntry with capture_pageview: "history_change", and import posthog in the page instead of using window.posthog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: 5115f2a3-23ac-46d3-9f8e-d9dbae3ab94d
@sarahxsanders sarahxsanders self-assigned this Nov 13, 2026
Explain that defaults dated 2025-05-24 or later already enable history_change pageviews, and add migration steps from gatsby-plugin-posthog, including removing manual onRouteUpdate pageviews to prevent duplicates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: 5115f2a3-23ac-46d3-9f8e-d9dbae3ab94d
@sarahxsanders
sarahxsanders marked this pull request as ready for review November 13, 2026 14:09
@sarahxsanders
sarahxsanders requested a review from a team as a code owner November 13, 2026 14:09
@edwinyjlim
edwinyjlim merged commit cdcd9e3 into main Nov 13, 2026
17 checks passed
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.

2 participants