diff --git a/package.json b/package.json index 35f54fe92..122ff8bed 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@trpc/next": "^10.0.0-rc.8", "@trpc/react-query": "^10.0.0-rc.8", "@trpc/server": "^10.0.0-rc.8", + "@vercel/analytics": "^0.1.8", "accept-language-parser": "^1.5.0", "autoprefixer": "^10.4.2", "axios": "^0.24.0", diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 83f844851..7af15cef2 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -3,12 +3,14 @@ import "tailwindcss/tailwind.css"; import "~/style.css"; import { Inter, Noto_Sans_Mono } from "@next/font/google"; +import { inject } from "@vercel/analytics"; import { NextPage } from "next"; import { AppProps } from "next/app"; import Head from "next/head"; import { appWithTranslation } from "next-i18next"; import PlausibleProvider from "next-plausible"; import { DefaultSeo } from "next-seo"; +import React from "react"; import { Toaster } from "react-hot-toast"; import Maintenance from "@/components/maintenance"; @@ -30,6 +32,13 @@ const noto = Noto_Sans_Mono({ const MyApp: NextPage = ({ Component, pageProps }) => { useCrispChat(); + React.useEffect(() => { + if (process.env.NEXT_PUBLIC_ENABLE_ANALYTICS) { + // calling inject directly to avoid having this run for self-hosted instances + inject(); + } + }, []); + if (process.env.NEXT_PUBLIC_MAINTENANCE_MODE === "1") { return ; } diff --git a/yarn.lock b/yarn.lock index c689a24f3..d9868e8d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2115,6 +2115,11 @@ "@typescript-eslint/types" "5.21.0" eslint-visitor-keys "^3.0.0" +"@vercel/analytics@^0.1.8": + version "0.1.8" + resolved "https://registry.yarnpkg.com/@vercel/analytics/-/analytics-0.1.8.tgz#71f1f8c7bb98ac0c5c47eb3fb8ccbe8141b9fe47" + integrity sha512-PQrOI8BJ9qUiVJuQfnKiJd15eDjDJH9TBKsNeMrtelT4NAk7d9mBVz1CoZkvoFnHQ0OW7Xnqmr1F2nScfAnznQ== + "@xobotyi/scrollbar-width@^1.9.5": version "1.9.5" resolved "https://registry.npmjs.org/@xobotyi/scrollbar-width/-/scrollbar-width-1.9.5.tgz"