Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

update ttfb calc to industry standard, fix LCP bug

Francis Cao9d72f8803a98
diff --git a/src/tracker/index.js b/src/tracker/index.js
index e7c8da562..6f79feb11 100644
--- a/src/tracker/index.js
+++ b/src/tracker/index.js
@@ -232,6 +232,7 @@
const metrics = {};
let sent = false;
let timeoutId;
+ let isInitialLoad = true;
const observe = (type, callback) => {
try {
@@ -246,7 +247,7 @@
// TTFB
observe('navigation', entry => {
- metrics.ttfb = Math.max(entry.responseStart - entry.requestStart, 0);
+ metrics.ttfb = Math.max(entry.responseStart - entry.startTime, 0);
});
// FCP
@@ -295,10 +296,12 @@
};
const applyFallbackMetrics = () => {
+ if (!isInitialLoad) return;
+
if (metrics.ttfb === undefined) {
const navigation = getEntriesByType('navigation')?.[0];
if (navigation) {
- metrics.ttfb = Math.max(navigation.responseStart - navigation.requestStart, 0);
+ metrics.ttfb = Math.max(navigation.responseStart - navigation.startTime, 0);
}
}
@@ -333,6 +336,7 @@
flushPerformance = () => {
sendPerformance();
+ isInitialLoad = false;
Object.keys(metrics).forEach(k => {
delete metrics[k];
});