Skip to content

Commit

Permalink
chore(intergration/vercel): simplify analytics script
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun969 committed Feb 8, 2023
1 parent cd60166 commit ee6a7f7
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions packages/integrations/vercel/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getCLS, getFCP, getFID, getLCP, getTTFB } from 'web-vitals';

const vitalsUrl = 'https://vitals.vercel-analytics.com/v1/vitals';

type Options = { path: string; analyticsId: string; debug?: boolean };
type Options = { path: string; analyticsId: string };

const getConnectionSpeed = () => {
return 'connection' in navigator &&
Expand All @@ -24,14 +24,7 @@ const sendToAnalytics = (metric: Metric, options: Options) => {
value: metric.value.toString(),
speed: getConnectionSpeed(),
};

if (options.debug) {
// eslint-disable-next-line no-console
console.log('[Analytics]', metric.name, JSON.stringify(body, null, 2));
}

const blob = new Blob([new URLSearchParams(body).toString()], {
// This content type is necessary for `sendBeacon`
type: 'application/x-www-form-urlencoded',
});
if (navigator.sendBeacon) {
Expand All @@ -51,7 +44,7 @@ function webVitals() {
console.error('[Analytics] VERCEL_ANALYTICS_ID not found');
return;
}
const options = { path: window.location.pathname, analyticsId };
const options: Options = { path: window.location.pathname, analyticsId };
try {
getFID((metric) => sendToAnalytics(metric, options));
getTTFB((metric) => sendToAnalytics(metric, options));
Expand Down

0 comments on commit ee6a7f7

Please sign in to comment.