From d928bd1ffde61b12e92186938675a2a506cf8ad9 Mon Sep 17 00:00:00 2001 From: Ru Chern Chong Date: Thu, 2 Nov 2023 18:08:41 +0800 Subject: [PATCH] Add Google Analytics --- .env.example | 1 + .github/workflows/sst.yml | 2 ++ app/layout.tsx | 28 ++++++++++++++++++++++------ env.d.ts | 5 +++++ 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 .env.example create mode 100644 env.d.ts diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..2a84726 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +NEXT_PUBLIC_GA_MEASUREMENT_ID= diff --git a/.github/workflows/sst.yml b/.github/workflows/sst.yml index f57f8a9..c832746 100644 --- a/.github/workflows/sst.yml +++ b/.github/workflows/sst.yml @@ -12,6 +12,8 @@ permissions: jobs: DeployApp: runs-on: ubuntu-latest + env: + NEXT_PUBLIC_GOOGLE_ANALYTICS: ${{ vars.NEXT_PUBLIC_GOOGLE_ANALYTICS }} steps: - name: Git clone the repository uses: actions/checkout@v3 diff --git a/app/layout.tsx b/app/layout.tsx index 13bba9e..b1568cb 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,4 +1,6 @@ import type { Metadata } from "next"; +import { headers } from "next/headers"; +import Script from "next/script"; import { Inter } from "next/font/google"; import "./globals.css"; @@ -10,14 +12,28 @@ export const metadata: Metadata = { "Stay ahead of the electric vehicle (EV) revolution in Singapore with the latest Singapore EV trends. Discover the future of sustainable transportation, charging infrastructure, government incentives, and more. Explore how Singapore is driving the shift towards eco-friendly mobility. Stay informed and make informed choices with Singapore EV Trends.", }; -export default function RootLayout({ - children, -}: { - children: React.ReactNode; -}) { +const RootLayout = ({ children }: { children: React.ReactNode }) => { + const nonce = headers().get("x-nonce") as string; + const gaMeasurementId = process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID; + return ( + {children} ); -} +}; + +export default RootLayout; diff --git a/env.d.ts b/env.d.ts new file mode 100644 index 0000000..9580e72 --- /dev/null +++ b/env.d.ts @@ -0,0 +1,5 @@ +namespace NodeJS { + interface ProcessEnv { + [key: string]: string; + } +}