Skip to content

Add HubSpot cookie banner and consent-gated Amplitude to docs#32

Open
Kaysahni wants to merge 1 commit into
mainfrom
kanishk/add-cookie-consent-banner
Open

Add HubSpot cookie banner and consent-gated Amplitude to docs#32
Kaysahni wants to merge 1 commit into
mainfrom
kanishk/add-cookie-consent-banner

Conversation

@Kaysahni

Copy link
Copy Markdown
Collaborator

Summary

  • Adds hubspot.js and amplitude.js at repo root. Mintlify auto-loads any .js file in the content directory on every page.
  • hubspot.js injects the same HubSpot portal (23414950) used on flox.dev, but only on production hostnames. The cookie banner itself is rendered/configured by HubSpot portal settings (Privacy & Consent → Cookies), so updating banner copy or geo scope is done in HubSpot, not in code.
  • amplitude.js registers a _hsp.addPrivacyConsentListener callback and only loads Amplitude after analytics consent is granted. The init payload (autocapture flags, Session Replay sample rate) mirrors floxwebsite/src/lib/amplitude.tsx so docs analytics shape matches the website.
  • Production hostnames (flox.dev, www.flox.dev, flox.mintlify.dev) → "Production - Flox" Amplitude project (6f89e78c…). All other hostnames → "Test Project" (820bc93b…). Same split that floxwebsite and FloxHub use.
  • On localhost and branch previews, no HubSpot script loads, so the consent listener never fires and Amplitude never loads — keeping dev traffic out of analytics by construction.

Why gate HubSpot on hostname

floxwebsite/src/pages/_app.tsx only renders the HubSpot script when isProductionDeployment is true. The Mintlify .js files have no env-var system, so we replicate that gate by checking location.hostname. Without this, every localhost page load on a non-EU IP would auto-load Amplitude with the prod key (HubSpot fires its consent listener with analytics: true by default on origins it doesn't manage).

Test plan

  • npx mintlify dev on localhost: confirm no js.hs-scripts.com and no cdn.amplitude.com requests; window.amplitude is undefined.
  • Deploy to a branch preview, visit it: same as above (preview hostname not in PROD_HOSTS).
  • After merge, visit https://flox.dev/docs/ from an EU/CA IP: HubSpot cookie banner appears (per HubSpot portal geo config). Decline → no Amplitude requests. Accept → cdn.amplitude.com/script/6f89e78c…js loads, events POST to api2.amplitude.com.
  • After merge, visit https://flox.dev/docs/ from a US IP: HubSpot fires consent listener with analytics: true (matches website behavior), Amplitude loads against the prod project.
  • Confirm the Mintlify prod hostname currently in PROD_HOSTS (flox.mintlify.dev) still matches what Mintlify actually serves. If Mintlify migrates to a different prod hostname, update PROD_HOSTS in both files.

🤖 Generated with Claude Code

Mirror the consent + analytics pattern from flox.dev on the Mintlify
docs site. Adds two custom JS files that Mintlify auto-loads on every
page:

- hubspot.js: injects HubSpot tracking (portal 23414950, same as
  flox.dev) only on production hostnames. Portal config controls
  banner display.
- amplitude.js: registers a HubSpot privacy-consent listener and
  loads Amplitude only after analytics consent is granted. Routes
  prod hostnames to the "Production - Flox" project and all other
  hostnames to the "Test Project" key, matching the floxwebsite and
  FloxHub split.

PROD_HOSTS = flox.dev, www.flox.dev, flox.mintlify.dev. Any other
origin (localhost, branch previews) loads no HubSpot script and
therefore no Amplitude.

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

mintlify Bot commented Jun 29, 2026

Copy link
Copy Markdown

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

Project Status Preview Updated (UTC)
flox 🟢 Ready View Preview Jun 29, 2026, 6:50 PM

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

Comment thread hubspot.js
try {
if (typeof window === 'undefined') return;

var PROD_HOSTS = ['flox.dev', 'www.flox.dev', 'flox.mintlify.dev'];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I recall there's a setting to add a domain to HubSpot for this to work, so it may be worth confirming.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Double checked. this is applicable if we go subdomain like docs.flox.dev apparently flox.dev/docs uses the same one as the main site.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, I was referring to the *.mintlify.dev domain.

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