feat: add termly cookie consent banner with cross-subdomain sync#188
feat: add termly cookie consent banner with cross-subdomain sync#188AlexKantor87 merged 3 commits intomainfrom
Conversation
Adds termly.js at the content root (Mintlify auto-includes any .js file on every page) and an integrations.cookies block in docs.json so Mintlify's own telemetry is gated on the kosli_consent localStorage flag that termly.js sets when the user accepts. The script also embeds a hidden iframe pointing at https://www.kosli.com/consent-sync.html so a user who already consented on the marketing site is not re-prompted on docs. Requires the companion www.kosli.com PR to relax frame-ancestors / X-Frame-Options on that path. Refs kosli-dev/server#5551 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
Code reviewFound 1 issue:
Lines 38 to 46 in c480f64 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
The previous code used window.addEventListener("termly.consent", ...)
which is not part of Termly's API and never fires. Switched to the
documented Termly.on("consent", callback) pattern with an onload
handler, and updated the embed script from the deprecated embed.min.js
(2021) to the current resource-blocker URL (2023).
Fix: use current Termly Event API (01dffa9)The original code used Changes:
Tested on preview environment:
|
Remaining console warnings after fixTwo warnings remain in the preview environment:
Neither warning affects the core consent flow —
|
unpkg.com and youtube.com are not used on the docs site — they were carried over from the www.kosli.com config.
## Summary - Adds MixPanel integration to `docs.json` with project token for docs analytics tracking ## Blocked This PR should not be merged until #188 has been merged. The Termly cookie consent banner must be in place before enabling MixPanel analytics, so that user consent is collected before any tracking fires. ## Test plan - [ ] Verify MixPanel events appear in the MixPanel dashboard after merging

Summary
termly.jsat the content root. Mintlify auto-includes any.jsfile there on every page, so this loads the Termly banner across all ofdocs.kosli.com.integrations.cookiesblock indocs.jsonpointing at thekosli_consentlocalStorage flag — Mintlify gates its own telemetry on this, so their analytics doesn't fire pre-consent (per https://www.mintlify.com/docs/integrations/privacy/overview#cookie-consent-and-disabling-telemetry).data-website-uuidaswww.kosli.com(single Termly property) plusdata-master-consents-origin="https://www.kosli.com"to read consent from the parent.https://www.kosli.com/consent-sync.htmlprovides Termly's documented cross-subdomain consent sharing, so users who already consented on the marketing site aren't re-prompted on docs.TERMLY_CUSTOM_BLOCKING_MAPincludes"kosli.com": "essential"so Termly's auto-blocker doesn't sandbox the consent-sync iframe and break the handshake.window.__kosliTermlyLoaded) prevents duplicate iframes on Mintlify client-side route changes.termly.consentevent listener mirrors Termly's consent state to thekosli_consentlocalStorage flag that Mintlify reads.Why
Termly currently runs only on
www.kosli.com. Visitors landing directly ondocs.kosli.comare never prompted, which is a GDPR/ePrivacy gap. Mintlify doesn't expose<head>injection, so this uses the documented.js-in-content-root path plus the privacy integration.Dependencies
Land in this order:
frame-ancestors/X-Frame-Optionson/consent-sync.htmlso this iframe isn't blocked.Out-of-band setup (issue tracks): add
docs.kosli.comto Termly Scan Settings, confirm cookie domain is.kosli.com.Tracking issue: https://github.com/kosli-dev/server/issues/5551
Known limitation (documented in tracking issue)
Mintlify content-dir JS executes after hydration, so
data-auto-blockonly catches scripts that fire after Termly mounts. Mintlify's own telemetry is now gated byintegrations.cookiesso that's covered. Anything we embed in MDX that fires earlier (YouTube, Loom, etc.) is the residual risk — worth a network-tab audit before merge.Test plan
docs.jsonschema errors.https://www.kosli.com/consent-sync.htmlloads without CSP / X-Frame-Options errors in browser console (requires PR 1787 deployed first).localStorage.kosli_consent === "accepted".www.kosli.com→ banner does not re-appear (cross-subdomain sync working).🤖 Generated with Claude Code
closes #86