Skip to content

Commit

Permalink
feat: optionally disable Vercel's insights and analytics (#1362)
Browse files Browse the repository at this point in the history
* feat: optionally disable vercel insights and analytics

* Update .changeset/flat-tables-hang.md

Co-authored-by: Chancellor Clark <chancellor.clark@bigcommerce.com>

---------

Co-authored-by: Chancellor Clark <chancellor.clark@bigcommerce.com>
  • Loading branch information
deini and chanceaclark authored Sep 13, 2024
1 parent 6d7c508 commit 0814afe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .changeset/flat-tables-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@bigcommerce/catalyst-core": minor
---
If app is not running on Vercel's infra, `<Analytics />` and `<SpeedInsights />` are not rendered.

Opt-out of vercel analytics and speed insights by setting the following env vars to `true`

- `DISABLE_VERCEL_ANALYTICS`
- `DISABLE_VERCEL_SPEED_INSIGHTS`
16 changes: 14 additions & 2 deletions core/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ export async function generateMetadata(): Promise<Metadata> {
};
}

const VercelComponents = () => {
if (process.env.VERCEL !== '1') {
return null;
}

return (
<>
{process.env.DISABLE_VERCEL_ANALYTICS !== 'true' && <Analytics />}
{process.env.DISABLE_VERCEL_SPEED_INSIGHTS !== 'true' && <SpeedInsights />}
</>
);
};

interface Props extends PropsWithChildren {
params: { locale: string };
}
Expand All @@ -78,8 +91,7 @@ export default function RootLayout({ children, params: { locale } }: Props) {
<NextIntlClientProvider locale={locale} messages={messages}>
<Providers>{children}</Providers>
</NextIntlClientProvider>
<Analytics />
<SpeedInsights />
<VercelComponents />
</body>
</html>
);
Expand Down

0 comments on commit 0814afe

Please sign in to comment.