Repository navigation
chore: route preview deployments to staging PostHog key - #830
Merged
Merged
Conversation
Mintlify auto-includes every .js file in the content directory on every page, so posthog-init.js previously ran with a single hardcoded key on both production and PR preview deployments. Select the PostHog project key at runtime based on hostname: docs.openhands.dev uses the production key, while *.mintlify.site / *.mintlify.app previews and localhost use a staging key. The staging key is a placeholder until the real value is dropped in; until then previews warn in the console and skip init. Co-authored-by: openhands <openhands@all-hands.dev>
Contributor
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Replace the staging key placeholder with the real staging project key so PR preview deployments report to the staging PostHog project. Removes the now-dead placeholder guard that skipped init when the placeholder was present. Co-authored-by: openhands <openhands@all-hands.dev>
2 tasks done
This branch was successfully deployed
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.
Problem
openhands/posthog-init.jscontained a single hardcoded PostHog project key. Because Mintlify auto-includes every.jsfile in the content directory on every page, that key ran identically on:docs.openhands.dev*.mintlify.site/*.mintlify.appURLs Mintlify generates automaticallySo all preview/PR traffic was being captured into the production PostHog project, polluting prod analytics. Unlike the
company-websiterepo (which uses Vercel env vars scoped per environment), the docs repo has no build-time env-var layer available in its Mintlify deploy model.Solution
Select the PostHog project key at runtime based on
window.location.hostname:docs.openhands.dev(prod custom domain)PROD_KEY(existing production key)*.mintlify.site/*.mintlify.app(PR previews)STAGING_KEYlocalhost/127.0.0.1/0.0.0.0(local dev)STAGING_KEYPROD_KEY(safe default)The
api_host(https://z.openhands.dev),ui_host,defaults, andperson_profilesconfig are unchanged for both environments.Why hostname detection instead of env vars / Mintlify native integration
.envfiles or build templating exist.integrations.posthog.apiKeyindocs.jsonwas considered but rejected: it routes through Mintlify's proxy (ph.mintlify.com), uses a single static key, and auto-opts-out of capturing on previews — giving "no analytics on previews" rather than "staging analytics on previews".<branch>-<subdomain>.mintlify.site), so hostname is a reliable runtime differentiator.Verification of routing logic
Extracted the
isStagingHostnamelogic and tested all branches:File also passes
node --check.Confirmed that staging posthog is receiving events as expected.
How to verify after merge
docs.openhands.dev): open DevTools → Network, filterposthog; confirmdecide/batchrequests still go tohttps://z.openhands.devand events land in the production PostHog project.*.mintlify.site):https://z.openhands.devbut events land in the staging PostHog project.posthog.initsnippet autoloadsarray.js), so look for$pageviewand$autocaptureclick events — there are no custom named events in docs (unlike company-website'shomepage_*events).Notes / follow-ups
PRODUCTION_HOSTNAMESarray.reo-init.jssibling script untouched (separate Reo.dev tracking, out of scope).@malhotra5 can click here to continue refining the PR