Send page views through langx.io, because blockers drop PostHog's host - #164
Merged
Conversation
PostHog's own setup check warns about this: events went straight to eu.i.posthog.com, which every blocklist carries, so an unknown share of visits was dropped before it was sent. `functions/relay/[[path]].js` is a Cloudflare Pages Function that forwards `/relay/*` to PostHog's EU cloud — ingestion to eu.i.posthog.com, `/static/` to eu-assets.i.posthog.com — and the SDK now points at `/relay` on whatever origin served the page, so a pages.dev preview proxies through its own copy. `VITE_POSTHOG_HOST` stays the escape hatch and is the only way to reach PostHog directly, which is what `npm run dev` needs. Nothing changed about what is sent: the same page views and two events, still cookieless, and the hop strips any cookie before forwarding. The cookie policy said in so many words that the connection was made from your browser directly rather than through us, which is no longer true, so §3.4 now describes the forwarding and why we did it; the privacy policy gets the same sentence. The deploy needed one adjustment: Wrangler compiles Functions from a `functions/` directory in its working directory, not from inside the directory it publishes, and the deploy job only unpacks the artifact. Naming two upload paths keeps the workspace as the artifact root, so `build/` and `functions/` arrive side by side — hence `directory: 'build'` rather than `'.'`. Verified locally: `wrangler pages functions build` compiles it and generates `include: ["/relay/*"]`, so no other path invokes a Function; the forwarding was exercised against a stubbed fetch for a POST event, a `/static/` asset and a bare `/relay`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WVA9XXNJJkvUDrNqztc39t
Both sides rewrote the same two paragraphs. main named the Cloudflare Web Analytics that was already there, taking §3.4 from two third-party connections to three; this branch replaced the sentence in that paragraph saying the PostHog connection is made from your browser directly. Kept main's structure — three things named, Cloudflare among them — with the proxy description in place of the sentence it made untrue, and the same in the privacy policy's website paragraph, which main had already split in two. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WVA9XXNJJkvUDrNqztc39t
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.
PostHog's setup check warns about this: events went straight to
eu.i.posthog.com, a host every blocklist carries, so an unknown share of visits was dropped before it was ever sent. Requests to langx.io are not blocked, because blocking them would break the site.What changed
functions/relay/[[path]].js— a Cloudflare Pages Function that forwards/relay/*to PostHog's EU cloud: ingestion toeu.i.posthog.com,/static/toeu-assets.i.posthog.com. It drops thecookieheader before forwarding, and does no caching of its own — Workers'fetchalready puts GET subrequests through Cloudflare's cache under the origin's headers. The site isadapter-static, so this is the only server it has.src/lib/analytics.ts—api_hostis now/relayon whatever origin served the page rather than a hardcodedhttps://langx.io, so a pages.dev preview proxies through its own copy.ui_hostpoints at the dashboard, which the SDK can no longer infer.VITE_POSTHOG_HOSTstays the escape hatch and is now the only way to reach PostHog directly — which is whatnpm run devneeds, since it serves no Function..github/workflows/deploy.yml— Wrangler compiles Functions from afunctions/directory in its working directory, not from inside the directory it publishes, and the deploy job only unpacks the artifact. Naming two upload paths keeps the workspace as the artifact root, sobuild/andfunctions/arrive side by side; hencedirectory: 'build'rather than'.'.PRODUCT.mdnotes the one path that is no longer a file.Nothing changed about what is sent: the same page views and two events, still cookieless, still nothing written to the visitor's browser.
Verification
wrangler@3 pages functions buildcompiles the Function and generatesinclude: ["/relay/*"], so no other path invokes it.fetchfor a POST event, a/static/asset, a preview origin and a bare/relay: prefix stripped, query and method and body preserved, cookie dropped, asset host split.npm run lintclean,npm run check0 errors,vite buildsucceeds and the built bundle no longer containseu.i.posthog.com.The PostHog warning clears on its own once the first events arrive through the proxy.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WVA9XXNJJkvUDrNqztc39t
Generated by Claude Code