Skip to content

Commit

Permalink
Add reportWebVitalsWithPath
Browse files Browse the repository at this point in the history
  • Loading branch information
bahlo committed Jun 27, 2023
1 parent 60501b9 commit f441e3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { reportWebVitals } from './webVitals';
export { reportWebVitals, reportWebVitalsWithPath } from './webVitals';
export { log, Logger } from './logger';
export {
withAxiom,
Expand Down
7 changes: 6 additions & 1 deletion src/webVitals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ const throttledSendMetrics = throttle(sendMetrics, 1000);
let collectedMetrics: WebVitalsMetric[] = [];

export function reportWebVitals(metric: NextWebVitalsMetric) {
collectedMetrics.push({ route: window.__NEXT_DATA__?.page, ...metric });
reportWebVitalsWithPath(metric);
}

export function reportWebVitalsWithPath(metric: NextWebVitalsMetric, path?: string) {
const route = path || window.__NEXT_DATA__?.page;
collectedMetrics.push({ route, ...metric });
// if Axiom env vars are not set, do nothing,
// otherwise devs will get errors on dev environments
if (!config.isEnvVarsSet()) {
Expand Down

0 comments on commit f441e3a

Please sign in to comment.