Skip to content

Commit

Permalink
Update sendToAnalytics() code example
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwalton committed Oct 22, 2020
1 parent 56c736b commit f461ce0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ The `sendToAnalytics()` function uses the [`navigator.sendBeacon()`](https://dev
import {getCLS, getFID, getLCP} from 'web-vitals';

function sendToAnalytics(metric) {
const body = JSON.stringify(metric);
const body = JSON.stringify({[metric.name]: metric.value});
// Use `navigator.sendBeacon()` if available, falling back to `fetch()`.
(navigator.sendBeacon && navigator.sendBeacon('/analytics', body)) ||
fetch('/analytics', {body, method: 'POST', keepalive: true});
Expand Down

0 comments on commit f461ce0

Please sign in to comment.