History

Capture pageviews on the marketing site (#1655)

UTM-tagged landings on executor.sh produced no $pageview, so campaigns read as zero traffic in PostHog. The params only reached $web_vitals, which no funnel or web-analytics view uses. Autocapture stays off.

Rhys Sullivan committed 2 months ago

Commit 34f37201 parent 1c24f561 file · +11 −4Browse files

Unified · Split

apps/marketing/src/layouts/Layout.astro+11−4
@@ -50,9 +50,16 @@ const canonical = new URL(Astro.url.pathname, Astro.site ?? Astro.url).toString( · 49 unmodified lines
5050 // deploy env, so it's a no-op in dev / unconfigured builds (and the SDK
5151 // isn't even shipped, thanks to the dynamic import). Events are proxied
5252 // first-party through src/middleware.ts to survive adblockers.
53− // autocapture and pageviews are off on purpose: we only send the explicit
54− // events the page fires (e.g. the "Set up with your agent" copy). Flip
55− // capture_pageview on if you want a denominator for conversion.
53+ // autocapture stays off on purpose: beyond $pageview we only send the
54+ // explicit events the page fires (e.g. the "Set up with your agent" copy).
55+ //
56+ // capture_pageview is ON because this is the campaign landing surface.
57+ // With it off, a visit to executor.sh/?utm_source=... produced no
58+ // $pageview at all, so every UTM-tagged campaign read as zero traffic in
59+ // PostHog — the params only ever reached $web_vitals, which no funnel or
60+ // web-analytics view is built on. Astro serves a full page load per
61+ // navigation, so plain `true` (capture once on init) is right here;
62+ // `history_change` is for SPAs like apps/cloud.
5663 const phKey = import.meta.env.PUBLIC_POSTHOG_KEY;
5764 if (phKey) {
5865 // api_host rides the `/_astro` prefix that the cloud edge forwards to
@@ -62,7 +69,7 @@ const canonical = new URL(Astro.url.pathname, Astro.site ?? Astro.url).toString( · 3 unmodified lines
6269 api_host: `${window.location.origin}/_astro/_ph`,
6370 ui_host: import.meta.env.PUBLIC_POSTHOG_HOST ?? "https://us.posthog.com",
6471 autocapture: false,
65− capture_pageview: false,
72+ capture_pageview: true,
6673 persistence: "localStorage",
6774 });
6875 return posthog;