From 596daf83791945d48e732e7e2e80db0c347f25be Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 5 Oct 2026 07:19:32 +0000 Subject: [PATCH] feat: expose window.posthog after idle init for hire events (#1574) Assign posthog instance to window.posthog after posthog.init(...) in PostHog.astro so hire-analytics can capture named hire events. Co-authored-by: alehar9320 <5390430+alehar9320@users.noreply.github.com> --- src/__tests__/identity.test.ts | 10 ++++++++++ src/components/PostHog.astro | 1 + 2 files changed, 11 insertions(+) diff --git a/src/__tests__/identity.test.ts b/src/__tests__/identity.test.ts index 71210938..028fd45c 100644 --- a/src/__tests__/identity.test.ts +++ b/src/__tests__/identity.test.ts @@ -2807,4 +2807,14 @@ describe('identity copy', () => { expect(contact).toContain('min-height: 44px'); expect(contact).toContain('min-width: 44px'); }); + + it('exposes window.posthog after idle init so hire Contact card can capture (#hire-ph)', () => { + const ph = readFileSync('src/components/PostHog.astro', 'utf8'); + expect(ph).toContain("await import('posthog-js')"); + expect(ph).toContain('posthog.init('); + expect(ph).toMatch(/window\.posthog\s*=\s*posthog/); + expect(ph).toContain('PUBLIC_POSTHOG_KEY'); + expect(ph).toContain('requestIdleCallback'); + expect(ph).not.toMatch(/^import\s+.*from\s+['"]posthog-js['"]/m); + }); }); diff --git a/src/components/PostHog.astro b/src/components/PostHog.astro index 0be0f2d6..4ee32470 100644 --- a/src/components/PostHog.astro +++ b/src/components/PostHog.astro @@ -15,6 +15,7 @@ api_host: posthogHost, person_profiles: 'identified_only', }); + window.posthog = posthog; } const scheduleIdle =