Skip to content

Add PostHog and GA4 behind the consent banner - #2540

Draft
alexleventer wants to merge 1 commit into
mainfrom
docs-analytics-consent
Draft

alexleventer wants to merge 1 commit into
mainfrom
docs-analytics-consent

Conversation

@alexleventer

Copy link
Copy Markdown
Contributor

Part of superfly/docs-tracking#304. Depends on superfly/ui-ex#5903, which is waiting on #security. Until that ships, this script fails closed and loads nothing.

What it does (fly-analytics.js, a port of landing's posthog-consent.js):

  • It's one self-contained file, because Mintlify runs content-dir JS in no guaranteed order. It loads the vendored no-external-code PostHog bundle from fly.io/static/javascripts/posthog.js itself, so it doesn't depend on auth-nav.js or any other file. It touches nothing auth-nav.js uses.
  • It fetches https://fly.io/api/consent-scope with credentials. Logged-in visitors get no tracking at all. If the fetch fails, as on Mintlify previews, mint dev or network errors, nothing loads.
  • EEA/UK visitors get the same banner and copy as fly.io. PostHog starts opted out with memory persistence, and Google Consent Mode defaults to denied until they click Accept. The banner is styled in styles.css with dark mode support.
  • PostHog uses capture_pageview: "history_change", because Mintlify navigates client-side.
  • GA4/GTM go through the analytics.fly.io proxy, same as fly.io.
  • docs.json gets a Legal footer with Privacy Policy and a "Cookie preferences" link that reopens the banner.

Not tested in a browser yet: the CORS change has to be live first. To check after it ships, load docs.fly.io logged out and confirm posthog.fly.io requests and $pageview on navigation. Logged in, there should be none. Through an EEA edge, the banner should show.

Plausible is unchanged. CSP directives for Mintlify are still a separate open item.

🤖 Generated with Claude Code

Ports landing's posthog-consent.js to Mintlify as one self-contained
file: it loads the vendored PostHog bundle from fly.io, asks
fly.io/api/consent-scope for the EEA/UK and logged-in checks, and shows
the same banner. Pageviews are captured on client-side route changes.
A Legal footer adds a Cookie preferences link to reopen the banner.

Refs superfly/docs-tracking#304

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

mintlify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

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

Project Status Preview Updated
fly-io 🟢 Ready View Preview Oct 8, 2026, 11:04 PM

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

This branch was successfully deployed

1 active deployment
staging — 0e445469 Deployed Oct 8, 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.

1 participant