diff --git a/.env b/.env index 0d00742..c62eabf 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ -BUILD_SERVER_BASE_URL=https://playground.test.aelf.dev \ No newline at end of file +BUILD_SERVER_BASE_URL= +GA_TAG= \ No newline at end of file diff --git a/app/layout.tsx b/app/layout.tsx index 36c0e21..3b97e6a 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -5,6 +5,8 @@ import { ThemeProvider } from "@/components/theme-provider"; import { PropsWithChildren } from "react"; import TopMenu from "@/components/top-menu"; import clsx from "clsx"; +import { GoogleAnalytics } from "@next/third-parties/google"; +import { getGoogleAnalyticsTag } from "@/lib/env"; const font = Poppins({ weight: ["100", "200", "300", "400", "500", "600", "700", "800", "900"], @@ -17,6 +19,8 @@ export const metadata: Metadata = { }; export default function RootLayout({ children }: PropsWithChildren) { + const gaId = getGoogleAnalyticsTag(); + return ( @@ -30,6 +34,7 @@ export default function RootLayout({ children }: PropsWithChildren) {
{children}
+ {gaId ? : null} ); } diff --git a/lib/env.ts b/lib/env.ts index a5334fa..cbb9f19 100644 --- a/lib/env.ts +++ b/lib/env.ts @@ -1,7 +1,15 @@ import { unstable_noStore as noStore } from "next/cache"; -export function getBuildServerBaseUrl() { +function getEnv(key: string) { noStore(); - return process.env["BUILD_SERVER_BASE_URL"]; + return process.env[key]; } + +export function getBuildServerBaseUrl() { + return getEnv("BUILD_SERVER_BASE_URL"); +} + +export function getGoogleAnalyticsTag() { + return getEnv("GA_TAG"); +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 373671b..8017397 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "@codemirror/language": "^6.10.2", "@codemirror/legacy-modes": "^6.4.0", "@hookform/resolvers": "^3.9.0", + "@next/third-parties": "^14.2.5", "@radix-ui/react-accordion": "^1.2.0", "@radix-ui/react-dialog": "^1.1.1", "@radix-ui/react-dropdown-menu": "^2.1.1", @@ -685,6 +686,19 @@ "node": ">= 10" } }, + "node_modules/@next/third-parties": { + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/third-parties/-/third-parties-14.2.5.tgz", + "integrity": "sha512-PDRJm8RZ3rnGNporHKjcdCeZqoW8iJ5uP0clo1Z08TqJiQzuntJ66zrGYCJyqTakx62UJNOp73YsQCFo6kbYYg==", + "license": "MIT", + "dependencies": { + "third-party-capital": "1.0.20" + }, + "peerDependencies": { + "next": "^13.0.0 || ^14.0.0", + "react": "^18.2.0" + } + }, "node_modules/@noble/hashes": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.4.0.tgz", @@ -6971,6 +6985,12 @@ "node": ">=0.8" } }, + "node_modules/third-party-capital": { + "version": "1.0.20", + "resolved": "https://registry.npmjs.org/third-party-capital/-/third-party-capital-1.0.20.tgz", + "integrity": "sha512-oB7yIimd8SuGptespDAZnNkzIz+NWaJCu2RMsbs4Wmp9zSDUM8Nhi3s2OOcqYuv3mN4hitXc8DVx+LyUmbUDiA==", + "license": "ISC" + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", diff --git a/package.json b/package.json index aebfaf9..d34072c 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "@codemirror/language": "^6.10.2", "@codemirror/legacy-modes": "^6.4.0", "@hookform/resolvers": "^3.9.0", + "@next/third-parties": "^14.2.5", "@radix-ui/react-accordion": "^1.2.0", "@radix-ui/react-dialog": "^1.1.1", "@radix-ui/react-dropdown-menu": "^2.1.1",