The clipboard handler now asks for a capture via a DOM event (analytics:capture) that the gated PostHog init listens for, instead of reaching through a window double cast. Fixes the lint rule that banned casting through unknown.
Unified · Split
| @@ -67,7 +67,17 @@ const canonical = new URL(Astro.url.pathname, Astro.site ?? Astro.url).toString( · 66 unmodified lines | ||
| 67 | 67 | capture_pageview: false, |
| 68 | 68 | persistence: "localStorage", |
| 69 | 69 | }); |
| 70 | − Object.assign(window, { posthog }); | |
| 70 | + // The copy handler (in index.astro) is a separate bundle, so it asks | |
| 71 | + // for a capture via a DOM event rather than reaching for a global. | |
| 72 | + window.addEventListener("analytics:capture", (e) => { | |
| 73 | + const detail = ( | |
| 74 | + e as CustomEvent<{ | |
| 75 | + event: string; | |
| 76 | + properties?: Record<string, unknown>; | |
| 77 | + }> | |
| 78 | + ).detail; | |
| 79 | + posthog.capture(detail.event, detail.properties); | |
| 80 | + }); | |
| 71 | 81 | }); |
| 72 | 82 | } |
| 73 | 83 | </script> |
| @@ -442,13 +442,11 @@ Source (and the place to start if something breaks): https://github.com/RhysSull · 441 unmodified lines | ||
| 442 | 442 | btn.dataset.copied = "true"; |
| 443 | 443 | const event = btn.dataset.event; |
| 444 | 444 | if (event) { |
| 445 | − ( | |
| 446 | − window as unknown as { | |
| 447 | − posthog?: { | |
| 448 | − capture: (e: string, p?: Record<string, unknown>) => void; | |
| 449 | − }; | |
| 450 | − } | |
| 451 | − ).posthog?.capture(event, { surface: "marketing_hero" }); | |
| 445 | + window.dispatchEvent( | |
| 446 | + new CustomEvent("analytics:capture", { | |
| 447 | + detail: { event, properties: { surface: "marketing_hero" } }, | |
| 448 | + }), | |
| 449 | + ); | |
| 452 | 450 | } |
| 453 | 451 | } catch { |
| 454 | 452 | btn.dataset.copied = "false"; |