Skip to content

Commit

Permalink
feat: ga
Browse files Browse the repository at this point in the history
  • Loading branch information
yongenaelf committed Jul 26, 2024
1 parent 2e68e79 commit a3d6148
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
BUILD_SERVER_BASE_URL=https://playground.test.aelf.dev
BUILD_SERVER_BASE_URL=
GA_TAG=
5 changes: 5 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -17,6 +19,8 @@ export const metadata: Metadata = {
};

export default function RootLayout({ children }: PropsWithChildren) {
const gaId = getGoogleAnalyticsTag();

return (
<html lang="en">
<body className={clsx(font.className, "overflow-hidden")}>
Expand All @@ -30,6 +34,7 @@ export default function RootLayout({ children }: PropsWithChildren) {
<main className="h-[calc(100vh-66px)] overflow-auto">{children}</main>
</ThemeProvider>
</body>
{gaId ? <GoogleAnalytics gaId={gaId} /> : null}
</html>
);
}
12 changes: 10 additions & 2 deletions lib/env.ts
Original file line number Diff line number Diff line change
@@ -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");
}
20 changes: 20 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a3d6148

Please sign in to comment.