Skip to content

Commit

Permalink
chore: add web vitals
Browse files Browse the repository at this point in the history
  • Loading branch information
icco committed Dec 7, 2024
1 parent f4ea891 commit 70a3509
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
max-width: 1200px;
}
</style>

<script type="module">
import { onCLS, onINP, onLCP, onFCP, onFID, onTTFB } from 'https://unpkg.com/web-vitals@4?module';

function sendToAnalytics(metric) {
const body = JSON.stringify(metric);
(navigator.sendBeacon && navigator.sendBeacon('https://reportd.natwelch.com/analytics/resume', body)) ||
fetch('https://reportd.natwelch.com/analytics/resume', { body, method: 'POST', keepalive: true });
}

onCLS(sendToAnalytics);
onFCP(sendToAnalytics);
onFID(sendToAnalytics);
onINP(sendToAnalytics);
onLCP(sendToAnalytics);
onTTFB(sendToAnalytics);
</script>
</head>

<body class="mx-auto p-6 md:p-24 bg-black text-white">
Expand Down
17 changes: 17 additions & 0 deletions templates/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
max-width: 1200px;
}
</style>

<script type="module">
import { onCLS, onINP, onLCP, onFCP, onFID, onTTFB } from 'https://unpkg.com/web-vitals@4?module';

function sendToAnalytics(metric) {
const body = JSON.stringify(metric);
(navigator.sendBeacon && navigator.sendBeacon('https://reportd.natwelch.com/analytics/reportd', body)) ||
fetch('https://reportd.natwelch.com/analytics/reportd', { body, method: 'POST', keepalive: true });
}

onCLS(sendToAnalytics);
onFCP(sendToAnalytics);
onFID(sendToAnalytics);
onINP(sendToAnalytics);
onLCP(sendToAnalytics);
onTTFB(sendToAnalytics);
</script>
</head>

<body class="mx-auto p-6 md:p-24 bg-black text-white">
Expand Down

0 comments on commit 70a3509

Please # to comment.