Skip to content

feat(docs): download links carry the docs visitor's PostHog id - #6468

Merged
jrusso1020 merged 2 commits into
mainfrom
feat/docs-download-ph-id
Oct 26, 2026
Merged

jrusso1020 merged 2 commits into
mainfrom
feat/docs-download-ph-id

Conversation

@jrusso1020

@jrusso1020 jrusso1020 commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds docs/download-attribution.js. Mintlify loads it on every page. When someone clicks a link to hyperframes.dev/studio/download, the script adds ph_id=<the docs' PostHog distinct_id> to it. The id comes from the docs' own posthog cookie. Afterwards the script restores the link, so a copied link never carries the id.

Why

The docs and hyperframes.dev send to the same PostHog project (356858). They are different domains, though, so the download route can't read the docs' cookie. A download clicked in the docs therefore lands under an id with none of that visit's pageviews. Since 2026-10-25 12:00 UTC, 977 downloads came from src=docs-* links, and only 2.8% share a distinct_id with any pageview.

Related work

Refs heygen-com/hyperframes-internal#6057. That PR makes the route read ph_id. Until it ships, the route ignores the extra parameter.

How

  • Capture-phase click and auxclick listeners on document, so middle-clicks and Mintlify's client-side navigation are covered without per-link wiring. Same approach as template-gallery.js.
  • The id is read from the cookie, not window.posthog, because Mintlify bundles posthog-js and does not expose it.
  • Mintlify runs every .js file in docs/ on every page (https://www.mintlify.com/docs/customize/custom-scripts#custom-javascript), so the file needs no other wiring.
  • The id is forwarded only to https://hyperframes.dev/studio/download, exactly. It is skipped when PostHog isn't loaded on the page, when the visitor opted out of posthog-js capture (__ph_opt_in_out_<token>), or when the browser sends Global Privacy Control or Do Not Track.
  • Only UUID-shaped ids are sent, and the route checks them again.

Test plan

  • Unit tests added/updated. The docs have no JS test harness.
  • Manual testing performed on this PR's unmodified Mintlify preview (https://hyperframes-feat-docs-download-ph-id.mintlify.site/quickstart) at 83ecb8f. All four download links got ph_id matching the page's own posthog-js id, and each href was restored afterwards. Other hosts, http:, opt-out (localStorage or cookie), GPC, DNT and PostHog not loaded all left the link unchanged. Earlier, I also injected the script into the live hyperframes.heygen.com/quickstart in headless Chrome and clicked the navbar, sidebar and quickstart download links. Each one followed ...?src=docs-navbar&ph_id=01a1797f-... (or docs-quickstart), and its href was back to the original afterwards. A GitHub link was left alone. The id matched distinct_id in the page's posthog-js localStorage.
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

oxlint docs/download-attribution.js reports 0 findings. docs/ is excluded from oxfmt.

Not exercised: a real click through to a PostHog event. Headless Chrome is dropped as a bot by posthog-js.

🤖 Generated with Claude Code

— Rames

hyperframes.dev counts each Studio download in PostHog, but it cannot read the
docs' posthog cookie (another domain), so a download clicked here lands under
an id with none of this visit's pageviews. A docs script now adds the id as
ph_id when a download link is clicked, and puts the link back afterwards so a
copied link never carries it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@mintlify

mintlify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
hyperframes 🟢 Ready View Preview Oct 26, 2026, 7:00 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@jerrai-bot-heygen jerrai-bot-heygen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wire the script into the actual Mintlify page load and verify a normal docs click, then restrict the ID-bearing URL to the intended HTTPS host and demonstrate that consent/opt-out suppresses transfer. The PR currently adds a standalone file without a loader; its manual test injected that file, so it does not validate the shipped path. — Jerrai

Comment thread docs/download-attribution.js Resolved
Comment thread docs/download-attribution.js Resolved
…with consent

The id now goes only to https://hyperframes.dev/studio/download, the one
address the docs link to, never another subdomain or plain http. It is not
forwarded when PostHog is not running on the page, when the visitor opted out
of PostHog capture, or when the browser sends Do Not Track or Global Privacy
Control.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@jerrai-bot-heygen jerrai-bot-heygen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 83ecb8f. My earlier loader finding was incorrect: Mintlify documents that .js files in the content directory load site-wide, and the author verified this script in an unmodified PR preview. The updated source restricts ID transfer to the exact HTTPS download endpoint and checks the PostHog opt-out state in browser storage, GPC, and DNT. Hosted docs validation and Mintlify deployment succeeded. I did not independently complete a browser-to-PostHog event or production logging/retention check; the author’s preview click covers the DOM/URL behavior. No code blocker remains. — Jerrai

@jrusso1020
jrusso1020 added this pull request to the merge queue Oct 26, 2026
Merged via the queue into main with commit 25b7cbd Oct 26, 2026
107 checks passed
@jrusso1020
jrusso1020 deleted the feat/docs-download-ph-id branch October 26, 2026 20:22

This branch was successfully deployed

1 active deployment
staging - docs — 83ecb8f8 Deployed Oct 26, 2026 by mintlify[bot]
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