Skip to content

Commit

Permalink
fix: 如果未设置统计的环境变量,则不加载相应的代码 #65
Browse files Browse the repository at this point in the history
  • Loading branch information
meetqy committed Mar 25, 2024
1 parent 5638499 commit dfc67cc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/app/metrics/google-analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import Script from "next/script";

const GoogleAnalytics = ({ id }: { id: string }) => {
const GoogleAnalytics = ({ id }: { id?: string }) => {
if (!id) return null;

return (
<>
<Script
Expand Down
4 changes: 3 additions & 1 deletion src/app/metrics/microsoft-clarity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import Script from "next/script";

const MicrosoftClarity = ({ id }: { id: string }) => {
const MicrosoftClarity = ({ id }: { id?: string }) => {
if (!id) return null;

return (
<Script
id="microsoft-clarity-init"
Expand Down
4 changes: 2 additions & 2 deletions src/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export default function Root({
</ThemeProvider>
</TRPCReactProvider>

<GoogleAnalytics id={process.env.NEXT_PUBLIC_GA_ID!} />
<MicrosoftClarity id={process.env.NEXT_PUBLIC_MC_ID!} />
<GoogleAnalytics id={process.env.NEXT_PUBLIC_GA_ID} />
<MicrosoftClarity id={process.env.NEXT_PUBLIC_MC_ID} />
<LoadFont />
{languageComponent && <Language />}
</body>
Expand Down

0 comments on commit dfc67cc

Please sign in to comment.