From 86f8eb3e6ddae9c79592c794f574377b474e3b96 Mon Sep 17 00:00:00 2001 From: Erosika Date: Thu, 27 Aug 2026 10:53:10 -0400 Subject: [PATCH] fix(docs): loader re-checks consent before init and captures SPA pageviews If consent is withdrawn while array.js downloads, sync() runs before window.posthog exists and the opt-out is skipped. onload now re-checks granted() and resets loaded so a later re-grant retries. Mintlify swaps pages without a reload, so capture_pageview: 'history_change' records navigation past the landing page. --- docs/posthog-consent.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/posthog-consent.js b/docs/posthog-consent.js index 3e93da82..acb47860 100644 --- a/docs/posthog-consent.js +++ b/docs/posthog-consent.js @@ -22,11 +22,17 @@ loaded = false } s.onload = function () { + // Consent withdrawn while array.js was downloading: skip init, allow a retry on re-grant. + if (!granted()) { + loaded = false + return + } window.posthog.init(KEY, { api_host: 'https://us.i.posthog.com', ui_host: 'https://us.posthog.com', cross_subdomain_cookie: true, person_profiles: 'identified_only', + capture_pageview: 'history_change', }) } document.head.appendChild(s)