Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error tracking example #113

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/nextjs/app/errors/error.tsx
@@ -0,0 +1,14 @@
'use client';
import { useEffect } from 'react';
import { track } from '@vercel/analytics';

export default function Error({ error }: { error: Error; reset: () => void }) {
useEffect(() => {
track('thrown-error', {
message: error.message,
time: new Date().toLocaleString(),
});
}, [error.message]);

return <div>Error</div>;
}
10 changes: 10 additions & 0 deletions apps/nextjs/app/errors/page.tsx
@@ -0,0 +1,10 @@
'use client';
import { useEffect } from 'react';

export default function ErrorPage() {
useEffect(() => {
throw new Error('Error!');
}, []);

return <div>I should error</div>;
}
3 changes: 3 additions & 0 deletions apps/nextjs/app/layout.tsx
@@ -1,3 +1,5 @@
import { Analytics } from '@vercel/analytics/react';

export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
Expand All @@ -10,6 +12,7 @@ export default function RootLayout({
}) {
return (
<html lang="en">
<Analytics />
<body>{children}</body>
</html>
);
Expand Down