Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,21 @@ const telemetryConfig = Astro.locals.telemetry?.clientConfig() ?? null;
<body>
<slot />
<script>
import { initTelemetry, trackPageview } from "@/lib/telemetry";
initTelemetry();
trackPageview(location.pathname, document.title);
// Telemetry is pure analytics — never let it sit on the load critical
// path. Lazy-import the chunk (web-vitals + AI client) and fire the first
// pageview only once the main thread is idle, so the slow App Insights
// /track round-trip happens well after load. web-vitals reads buffered
// LCP/FCP/CLS entries, so deferring registration doesn't lose metrics.
Comment on lines +116 to +118
const startTelemetry = () =>
import("@/lib/telemetry").then(({ initTelemetry, trackPageview }) => {
initTelemetry();
trackPageview(location.pathname, document.title);
});
Comment on lines +119 to +123
if ("requestIdleCallback" in window) {
requestIdleCallback(startTelemetry, { timeout: 4000 });
} else {
window.addEventListener("load", () => setTimeout(startTelemetry, 1), { once: true });
}
</script>
</body>
</html>