Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/website/instrumentation-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ describe('website posthog init options', () => {
autocapture: true,
capture_performance: { web_vitals: true },
person_profiles: 'always',
disable_surveys: true,
});
});

// Named for the same reason as the capture_pageview case below: the project's
// remote `surveys: false` does not stop posthog-js downloading surveys.js,
// so dropping this flag silently restores a 33.5KB fetch on every page.
it('keeps the surveys bundle from loading at all', () => {
expect(POSTHOG_INIT_OPTIONS.disable_surveys).toBe(true);
});

// Redundant with the toEqual above, deliberately: this IS the bug this fix
// exists for, and a named failure here is far more legible than an object
// diff. Do not "simplify" this away.
Expand Down
10 changes: 10 additions & 0 deletions apps/website/instrumentation-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ export const POSTHOG_INIT_OPTIONS = {
autocapture: true,
capture_performance: { web_vitals: true },
person_profiles: 'always',
/*
* The site runs no surveys, and the project's remote config already says
* `surveys: false` — but that does NOT stop the 33.5KB `surveys.js` download.
* 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 this client flag is checked before that load, so
* the project setting alone can never prevent it. Measured on production with
* mobile throttling, the bundle arrived at ~4.9s on every page.
*/
disable_surveys: true,
} satisfies Partial<PostHogConfig>;

if (shouldCaptureAnalytics({ token, captureLocal, host: browserHost })) {
Expand Down
Loading