Skip to content

Commit

Permalink
refactor(layout): 优化Google Analytics集成和代码结构
Browse files Browse the repository at this point in the history
改进marketing layout中的Google Analytics实现和整体代码组织

- 添加条件渲染以仅在环境变量存在时加载Google Analytics
- 重新排序导入语句以提高可读性
- 格式化代码以提高一致性和可读性
- 添加环境变量日志输出用于调试
- 调整组件属性格式以提高可读性
  • Loading branch information
zhanghuan committed Oct 10, 2024
1 parent acfe3aa commit 686d695
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/app/[locale]/(marketing)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { GoogleAnalytics } from "@next/third-parties/google";
import { useTranslations } from "next-intl";
import { unstable_setRequestLocale } from "next-intl/server";

import { getDocsConfig } from "@/config/docs";
import { getMarketingConfig } from "@/config/marketing";
import { NavMobile } from "@/components/layout/mobile-nav";
import { NavBar } from "@/components/layout/navbar";
import { SiteFooter } from "@/components/layout/site-footer";
import { getMarketingConfig } from "@/config/marketing";
import { useTranslations } from "next-intl";
import { getDocsConfig } from "@/config/docs";
import { GoogleAnalytics } from '@next/third-parties/google'

interface MarketingLayoutProps {
children: React.ReactNode;
Expand All @@ -24,17 +24,33 @@ export default function MarketingLayout({
const docsConfig = getDocsConfig(t);

const translations = {
adminPanel: t('Dashboard.sidebar.adminPanel'),
dashboard: t('Dashboard.sidebar.dashboard'),
login: t('Marketing.login'),
signUp: t('Marketing.signUp'),
adminPanel: t("Dashboard.sidebar.adminPanel"),
dashboard: t("Dashboard.sidebar.dashboard"),
login: t("Marketing.login"),
signUp: t("Marketing.signUp"),
};

console.log(
"NEXT_PUBLIC_GOOGLE_ANALYTICS: ",
process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS,
);

return (
<div className="flex min-h-screen flex-col">
<GoogleAnalytics gaId={process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS || ''} />
<NavMobile marketingConfig={marketingConfig} docsConfig={docsConfig} translations={translations} />
<NavBar scroll={true} marketingConfig={marketingConfig} docsConfig={docsConfig} translations={translations} />
{process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS && (
<GoogleAnalytics gaId={process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS} />
)}
<NavMobile
marketingConfig={marketingConfig}
docsConfig={docsConfig}
translations={translations}
/>
<NavBar
scroll={true}
marketingConfig={marketingConfig}
docsConfig={docsConfig}
translations={translations}
/>
<main className="flex-1">{children}</main>
<SiteFooter />
</div>
Expand Down

0 comments on commit 686d695

Please sign in to comment.