我试图启用谷歌分析与帮助react-ga钩子。
我在github上跟踪了他们的文档,我不知道为什么得不到任何数据,也不知道如何调试这些数据。我已经在每个页面上粘贴了这个ReactGA.initialize("G-NHW4EP16PN");代码,但是我仍然没有得到任何东西,而且在我的Firebase应用程序中也没有流配置。
import ReactGA from "react-ga";
function App() {
useEffect(() => {
ReactGA.initialize("G-NHW4EP16PN");
ReactGA.pageview(window.location.pathname + window.location.search);
console.log(window.location.pathname);
}, []);
return (
<>
<Suspense fallback={<LoadingWait src={LoadImg} />}>
<Router>
<Sidebar />
<Switch>
<Route component={Overview} path="/" exact={true} />
<Route component={Work} path="/work" />
<Route component={Services} path="/services" />
<Route component={Contact} path="/contact" />
<Route component={PageNotFound} />
</Switch>
</Router>
</Suspense>
</>
);
}
export default App;发布于 2021-04-20 16:28:04

初始化方法以一个通用的解析gaTrackingID作为其第一个参数。您正在发送它的G-NHW4EP16PN,这不是一个通用的分析跟踪id。我会再次检查您的帐户,您似乎试图发送一个GA4测量id代替。
ReactGA.initialize('UA-000000-01', {
debug: true,
titleCase: false,
gaOptions: {
userId: 123
}
});https://stackoverflow.com/questions/67181988
复制相似问题