:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(frontend): split app entry timing into navigation phases (#118236)
Paul D'Ambra967c78f21940
diff --git a/frontend/src/lib/utils/bootTiming.test.ts b/frontend/src/lib/utils/bootTiming.test.tsindex d46340d24581..1e423fff4019 100644--- a/frontend/src/lib/utils/bootTiming.test.ts+++ b/frontend/src/lib/utils/bootTiming.test.ts@@ -80,6 +80,47 @@ describe('bootTiming', () => {expect(capture).toHaveBeenCalledTimes(sends ? 1 : 0)})+ it.each([+ {+ name: 'splits the entry phase with navigation timing',+ navigationEntries: [{ type: 'navigate', requestStart: 120.4, responseStart: 310.6, responseEnd: 352.2 }],+ expected: {+ navigation_type: 'navigate',+ request_start_ms: 120,+ response_start_ms: 311,+ response_end_ms: 352,+ },+ },+ {+ name: 'still sends the event without a navigation entry',+ navigationEntries: [],+ expected: { navigation_type: null },+ },+ {+ name: 'still sends the event without the navigation timing API',+ navigationEntries: undefined,+ expected: { navigation_type: null },+ },+ ])('$name', async ({ navigationEntries, expected }) => {+ // jsdom has no performance.getEntriesByType, so the test adds it and removes it again.+ if (navigationEntries) {+ Object.defineProperty(performance, 'getEntriesByType', {+ configurable: true,+ value: () => navigationEntries,+ })+ }+ try {+ markAt(50, 'entry')+ markAt(900, 'scene_rendered')+ await flushSend()+ } finally {+ Reflect.deleteProperty(performance, 'getEntriesByType')+ }++ const { navigation_type, request_start_ms, response_start_ms, response_end_ms } = capture.mock.calls[0][1]+ expect({ navigation_type, request_start_ms, response_start_ms, response_end_ms }).toEqual(expected)+ })+it('reports a page hidden only between two marks', async () => {let visibilityState: DocumentVisibilityState = 'visible'jest.spyOn(document, 'visibilityState', 'get').mockImplementation(() => visibilityState)diff --git a/frontend/src/lib/utils/bootTiming.ts b/frontend/src/lib/utils/bootTiming.tsindex 23b88f6d8096..ca9ff296ce07 100644--- a/frontend/src/lib/utils/bootTiming.ts+++ b/frontend/src/lib/utils/bootTiming.ts@@ -14,9 +14,17 @@ const context: BootContext = {}let pageWasHidden = falselet sent = false-function getNavigationType(): string | null {+function getNavigationProperties(): Record<string, string | number | null> {const navigation = performance.getEntriesByType?.('navigation')[0] as PerformanceNavigationTiming | undefined- return navigation?.type ?? null+ if (!navigation) {+ return { navigation_type: null }+ }+ return {+ navigation_type: navigation.type,+ request_start_ms: Math.round(navigation.requestStart),+ response_start_ms: Math.round(navigation.responseStart),+ response_end_ms: Math.round(navigation.responseEnd),+ }}// A background tab throttles timers and skips rendering, so its boot times are not comparable.@@ -48,7 +56,7 @@ async function sendBootTiming(): Promise<void> {posthog.capture(BOOT_TIMING_EVENT, {...durations,...context,- navigation_type: getNavigationType(),+ ...getNavigationProperties(),page_was_hidden: pageWasHidden,sample_rate: SAMPLE_RATE,})