Skip to content

Commit

Permalink
Add Google Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
TyHil committed Oct 8, 2024
1 parent 62d3430 commit d30664e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ PSQL_PASS=
DATABASE_URL=
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
NEXT_PUBLIC_MEASUREMENT_ID=
```
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Sidebar from '@src/components/nav/Sidebar';
import { type Metadata } from 'next';

import { Analytics } from '@vercel/analytics/react';
import GoogleAnalytics from '@src/components/googleAnalytics';

const inter = Inter({
subsets: ['latin'],
Expand Down Expand Up @@ -43,6 +44,7 @@ export default function RootLayout({
}) {
return (
<html lang="en">
<GoogleAnalytics />
<body className={`font-sans ${inter.variable}`}>
<TRPCReactProvider headers={headers()}>
<Sidebar />
Expand Down
26 changes: 26 additions & 0 deletions src/components/googleAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Script from 'next/script';
import React from 'react';

const GoogleAnalytics = () => {
return (
<>
<Script
strategy="lazyOnload"
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_MEASUREMENT_ID}`}
/>

<Script id="" strategy="lazyOnload">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_MEASUREMENT_ID}', {
page_path: window.location.pathname,
});
`}
</Script>
</>
);
};

export default GoogleAnalytics;

0 comments on commit d30664e

Please sign in to comment.