(metric)
| 9 | } |
| 10 | |
| 11 | export function sendToVercelAnalytics(metric) { |
| 12 | const analyticsId = process.env.REACT_APP_VERCEL_ANALYTICS_ID |
| 13 | if (!analyticsId) { |
| 14 | return |
| 15 | } |
| 16 | |
| 17 | const body = { |
| 18 | dsn: analyticsId, |
| 19 | id: metric.id, |
| 20 | page: window.location.pathname, |
| 21 | href: window.location.href, |
| 22 | event_name: metric.name, |
| 23 | value: metric.value.toString(), |
| 24 | speed: getConnectionSpeed(), |
| 25 | } |
| 26 | |
| 27 | const blob = new Blob([new URLSearchParams(body).toString()], { |
| 28 | // This content type is necessary for `sendBeacon` |
| 29 | type: 'application/x-www-form-urlencoded', |
| 30 | }) |
| 31 | if (navigator.sendBeacon) { |
| 32 | navigator.sendBeacon(vitalsUrl, blob) |
| 33 | } else |
| 34 | fetch(vitalsUrl, { |
| 35 | body: blob, |
| 36 | method: 'POST', |
| 37 | credentials: 'omit', |
| 38 | keepalive: true, |
| 39 | }) |
| 40 | } |
nothing calls this directly
no test coverage detected