Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Google Analytics 4 Measurement ID. Leave empty to disable GA.
# Local dev: copy this file to `.env.local` and fill in your ID.
# Production: set as a GitHub Actions repository variable named NEXT_PUBLIC_GA_ID.
NEXT_PUBLIC_GA_ID=
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm build
env:
NEXT_PUBLIC_GA_ID: ${{ vars.NEXT_PUBLIC_GA_ID }}
- uses: actions/upload-pages-artifact@v3
with:
path: out
Expand Down
6 changes: 6 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import type { Metadata } from "next";
import { Inter, JetBrains_Mono } from "next/font/google";
import { GoogleAnalytics } from "@next/third-parties/google";
import "./globals.css";

// Set NEXT_PUBLIC_GA_ID (e.g. "G-XXXXXXXXXX") to enable Google Analytics.
// When unset (local dev, PR previews), GA is not loaded.
const gaId = process.env.NEXT_PUBLIC_GA_ID;

const inter = Inter({ subsets: ["latin"], variable: "--font-inter" });
const jetbrains = JetBrains_Mono({ subsets: ["latin"], variable: "--font-jetbrains" });

Expand All @@ -28,6 +33,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
<script dangerouslySetInnerHTML={{ __html: noFlash }} />
</head>
<body className="font-sans antialiased">{children}</body>
{gaId ? <GoogleAnalytics gaId={gaId} /> : null}
</html>
);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"author": "An-Ting Hsu",
"license": "MIT",
"dependencies": {
"@next/third-parties": "15",
"next": "15",
"react": "19",
"react-dom": "19"
Expand Down
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading