Set up PostHog reverse proxy for docs site#1510
Draft
samseely wants to merge 1 commit into
Draft
Conversation
- Add Next.js rewrites in next.config.js to proxy /ingest/* and /ingest/static/* to PostHog's us.i.posthog.com and us-assets.i.posthog.com endpoints - Update lib/posthog.ts to use /ingest as api_host and https://us.posthog.com as ui_host - This prevents ad blockers from blocking PostHog pageview tracking by routing requests through the docs site's own domain Resolves KNO-13949 Co-authored-by: Sam Seely <samseely@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR sets up a PostHog reverse proxy for the docs site to prevent ad blockers from blocking PostHog tracking requests. The docs site was sending PostHog events directly to
https://us.i.posthog.com, which is on default ad-blocker blocklists. Since the docs audience is primarily developers who commonly use ad blockers, this was causing significant underreporting of pageviews.Changes made:
Added Next.js rewrites in
next.config.jsto proxy PostHog traffic through first-party paths:/ingest/static/:path*→https://us-assets.i.posthog.com/static/:path*(for static assets)/ingest/:path*→https://us.i.posthog.com/:path*(for API requests)/ingest/decide→https://us.i.posthog.com/decide(for feature flag/decide endpoint)Updated
lib/posthog.tsto use the proxied paths:api_host: "/ingest"(routes through the local proxy)ui_host: "https://us.posthog.com"(for toolbar and session recording links)This follows PostHog's official Next.js reverse proxy documentation.
Screenshots
Network requests showing PostHog traffic routing through the
/ingestproxy path instead of external PostHog domains:Network tab showing PostHog requests going through the /ingest proxy
To show artifacts inline, enable in settings.
Linear Issue: KNO-13949