Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
add google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
gkorland committed Sep 12, 2023
1 parent feed7e6 commit 542051d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/components/GoogleAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Script from "next/script";

const GoogleAnalytics = ({ ga_id }: { ga_id: string }) => (
<>
<Script
async
src={`https://www.googletagmanager.com/gtag/js?
id=${ga_id}`}
></Script>
<Script
id="google-analytics"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${ga_id}');
`,
}}
></Script>
</>
);
export default GoogleAnalytics;
5 changes: 5 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import './globals.css'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import { NextAuthProvider } from "./providers";
import GoogleAnalytics from "@/app/components/GoogleAnalytics";

const inter = Inter({ subsets: ['latin'] })

Expand All @@ -19,6 +20,10 @@ export default function RootLayout({
return (
<html lang="en">
<body className={inter.className}>
{process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS ? (
<GoogleAnalytics ga_id=
{process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS} />
) : null}
<NextAuthProvider>{children}</NextAuthProvider>
</body>
</html>
Expand Down

0 comments on commit 542051d

Please sign in to comment.