0

我正在尝试在react-ga挂钩的帮助下启用谷歌分析。 我在github
上关注了他们的文档,我不知道为什么我没有得到任何数据,也不知道如何调试它。我已将此代码粘贴到每个页面上,但我仍然没有得到任何东西,而且我的 Firebase 应用程序中的流配置也是如此。ReactGA.initialize("G-NHW4EP16PN");

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;

4

1 回答 1

1

react-ga 自述文件

在此处输入图像描述

初始化方法将通用分析 gaTrackingID 作为其第一个参数。您发送的是 G-NHW4EP16PN,它不是通用分析跟踪 ID。我会再次检查您的帐户,您似乎正试图向其发送 GA4 测量 ID。

ReactGA.initialize('UA-000000-01', {
  debug: true,
  titleCase: false,
  gaOptions: {
    userId: 123
  }
});
于 2021-04-20T16:28:04.777 回答