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
50 // deploy env, so it's a no-op in dev / unconfigured builds (and the SDK50 // deploy env, so it's a no-op in dev / unconfigured builds (and the SDK
51 // isn't even shipped, thanks to the dynamic import). Events are proxied51 // isn't even shipped, thanks to the dynamic import). Events are proxied
52 // first-party through src/middleware.ts to survive adblockers.52 // first-party through src/middleware.ts to survive adblockers.
53 // autocapture and pageviews are off on purpose: we only send the explicit53 // autocapture stays off on purpose: beyond $pageview we only send the
54 // events the page fires (e.g. the "Set up with your agent" copy). Flip54 // explicit events the page fires (e.g. the "Set up with your agent" copy).
55 // capture_pageview on if you want a denominator for conversion.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.
56 const phKey = import.meta.env.PUBLIC_POSTHOG_KEY;63 const phKey = import.meta.env.PUBLIC_POSTHOG_KEY;
57 if (phKey) {64 if (phKey) {
58 // api_host rides the `/_astro` prefix that the cloud edge forwards to65 // 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
62 api_host: `${window.location.origin}/_astro/_ph`,69 api_host: `${window.location.origin}/_astro/_ph`,
63 ui_host: import.meta.env.PUBLIC_POSTHOG_HOST ?? "https://us.posthog.com",70 ui_host: import.meta.env.PUBLIC_POSTHOG_HOST ?? "https://us.posthog.com",
64 autocapture: false,71 autocapture: false,
65 capture_pageview: false,72 capture_pageview: true,
66 persistence: "localStorage",73 persistence: "localStorage",
67 });74 });
68 return posthog;75 return posthog;