History

marketing: avoid double cast in copy-button analytics

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.

Rhys Sullivan committed 4 months ago

Commit c8eefaf1 parent 164792d2 files · +16 −8Browse files

Unified · Split

2 files
  1. apps/marketing/src/layouts/Layout.astro +11 −1
  2. apps/marketing/src/pages/index.astro +5 −7
apps/marketing/src/layouts/Layout.astro+11−1
@@ -67,7 +67,17 @@ const canonical = new URL(Astro.url.pathname, Astro.site ?? Astro.url).toString( · 66 unmodified lines
67 capture_pageview: false,67 capture_pageview: false,
68 persistence: "localStorage",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 </script>83 </script>
apps/marketing/src/pages/index.astro+5−7
@@ -442,13 +442,11 @@ Source (and the place to start if something breaks): https://github.com/RhysSull · 441 unmodified lines
442 btn.dataset.copied = "true";442 btn.dataset.copied = "true";
443 const event = btn.dataset.event;443 const event = btn.dataset.event;
444 if (event) {444 if (event) {
445 (445 window.dispatchEvent(
446 window as unknown as {446 new CustomEvent("analytics:capture", {
447 posthog?: {447 detail: { event, properties: { surface: "marketing_hero" } },
448 capture: (e: string, p?: Record<string, unknown>) => void;448 }),
449 };449 );
450 }
451 ).posthog?.capture(event, { surface: "marketing_hero" });
452 }450 }
453 } catch {451 } catch {
454 btn.dataset.copied = "false";452 btn.dataset.copied = "false";

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t