Skip to content

Commit

Permalink
Merge pull request #127 from axiomhq/arne/allow-route-override
Browse files Browse the repository at this point in the history
Allow route override in reportWebVitals, bump version
  • Loading branch information
bahlo committed Jun 27, 2023
2 parents 60501b9 + a72c12e commit e6648d2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "next-axiom",
"description": "Send WebVitals from your Next.js project to Axiom.",
"version": "0.17.0",
"version": "0.18.0",
"author": "Axiom, Inc.",
"license": "MIT",
"contributors": [
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
@@ -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
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

1 comment on commit e6648d2

@vercel
Copy link

@vercel vercel bot commented on e6648d2 Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-axiom-example – ./

next-axiom-example.axiom.dev
next-axiom-example-lemon.vercel.app
next-axiom-example-git-main.axiom.dev

Please sign in to comment.