Skip to content

Stop posthog-js downloading surveys.js on every page - #1136

Merged
blove merged 1 commit into
mainfrom
blove/posthog-disable-surveys
Sep 23, 2026
Merged

blove merged 1 commit into
mainfrom
blove/posthog-disable-surveys

Conversation

@blove

@blove blove commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Turns off PostHog surveys on the website. The site runs none, but every page was still downloading the 33.5KB surveys.js bundle.

Why the project setting wasn't enough

The project's remote config already says surveys: false. posthog-js (1.372.6) loads the surveys extension as soon as that remote value has arrived, whatever it is:

if (!isUndefined(this.remoteSurveys) || this.config.advanced_enable_surveys) { loadExternalDependency(…, "surveys", …) }

It then does nothing with it. The client-side disable_surveys flag is checked before that line (in both loadIfEnabled() and the remote-config handler), so it's the only switch that prevents the download. Only the website initializes PostHog; cockpit doesn't.

Change

disable_surveys: true in POSTHOG_INIT_OPTIONS, with a comment explaining the quirk. That object is pinned with toEqual, so the spec states the new key, plus a named case — same pattern as the existing capture_pageview one — saying why removing it would silently bring the fetch back.

Verified

In a real browser, with PostHog's actual remote config served locally and every /ingest request intercepted (nothing sent to PostHog):

surveys.js requests web-vitals.js
prod as it is 1 loads
with disable_surveys 0 loads
  • nx test website, nx lint website, nx build website

🤖 Generated with Claude Code

The site runs no surveys and the project's remote config already says
`surveys: false`, yet every page fetched the 33.5KB surveys bundle. posthog-js
loads the extension once the remote value has arrived, whatever it is
(`if (!isUndefined(remoteSurveys) || advanced_enable_surveys)`), then does
nothing with it. Only the client `disable_surveys` flag is checked before
that load, so the project setting alone can never prevent it.

Verified in a real browser with PostHog's actual remote config served
locally and every /ingest request intercepted: prod as it is fetches
surveys.js once per page; with this flag, zero. web-vitals.js still loads.

POSTHOG_INIT_OPTIONS is pinned by `toEqual`, so the spec states the new key,
plus a named case explaining why dropping it silently restores the fetch.
@blove
blove enabled auto-merge (squash) September 23, 2026 03:51
@vercel

vercel Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
threadplane Ready Ready Preview Sep 23, 2026 3:54am UTC

Request Review

@github-actions github-actions Bot 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.

Automated approval: this PR received an intelligent (AI) code review. See the review comments on this PR.

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @blove's task in 0s —— View job


I'll analyze this and get back to you.

@blove
blove merged commit 4fae98f into main Sep 23, 2026
33 checks passed
@blove
blove deleted the blove/posthog-disable-surveys branch September 23, 2026 20:53

This branch was successfully deployed

1 active deployment
Preview – threadplane — ea7c4b6e Deployed Sep 23, 2026 by vercel[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