ReviewOS

also looking at this

stacks/stx

fix(bun-plugin): forward analytics config on the serve path (so plugin/native analytics inject)

#1760
Merged glennmichael123 wants to merge fix/forward-analytics-on-serve-path into main
1 file +15 -0
9 days ago

The bun-plugin dev server (stx-serve / bun packages/bun-plugin/dist/serve.js pages/) silently dropped analytics injection.

Two causes in packages/bun-plugin/src/serve.ts:

  1. It sources its main config from bunfig's loadConfig (the raw object) and only consults the loadStxConfig() result for _pluginComponentDirs/_pluginPageDirs. A plugin's setup() can mutate the loaded config — e.g. an analytics plugin setting analytics.{enabled,driver,custom} — but that mutation never reached the served config.
  2. The processDirectives options allowlist omitted analytics, so even a present analytics wouldn't be forwarded — and the injectAnalytics gate (opts.analytics?.enabled) was always falsy.

Fix: carry the plugin-mutated analytics from the loadStxConfig() result onto stxConfig, and add analytics to the options allowlist (both serve branches). Now both native providers (fathom/GA/plausible/self-hosted) and plugin-injected trackers inject on this serve path, matching the SSG and stx dev/stx serve CLI paths.

Surfaced while building the @stacksjs/ts-analytics stx plugin (stacksjs/ts-analytics#123), whose setup() adapts { appId } into analytics.custom.

🤖 Generated with Claude Code

1 changed file on the files tab, with 0 review threads.

Sign in to comment on this pull request.