diff --git a/app/components/AnalyticsGate.jsx b/app/components/AnalyticsGate.jsx new file mode 100644 index 0000000..10be6cf --- /dev/null +++ b/app/components/AnalyticsGate.jsx @@ -0,0 +1,29 @@ +'use client'; +import { useLayoutEffect, useState } from 'react'; +import Script from 'next/script'; + +export default function AnalyticsGate({ GA_ID }) { + const [enabled, setEnabled] = useState(false); + useLayoutEffect(() => { + try { + const href = window.location.href || ''; + setEnabled(href.includes('hzm0321')); + } catch {} + }, []); + + if (!enabled) return null; + + return ( + <> + + + ); +} diff --git a/app/layout.jsx b/app/layout.jsx index 5118050..954bf9d 100644 --- a/app/layout.jsx +++ b/app/layout.jsx @@ -1,5 +1,6 @@ import Script from 'next/script'; import './globals.css'; +import AnalyticsGate from './components/AnalyticsGate'; export const metadata = { title: '基估宝', @@ -13,21 +14,9 @@ export default function RootLayout({ children }) { - {/* Google Analytics */} - + {children}