我的控制台给了我路径名命中,但 GAnalytics 仪表板上没有记录
其中一个控制台
Running command: ga("create", "G-XXX", "auto")
analytics_debug.js:22
Running command: ga("send", {hitType: "pageview", page: "/site/646c4fd09cb36771adae634b/service-type/onsiteCollection/outlet/646c4d099cb36771adae6151/menus/646c5d6e9cb36771adae6ab3"})
我在我的index.html中添加了以下代码
<script async src="https://www.googletagmanager.com/gtag/js?id=%REACT_APP_MEASUREMENT_ID%"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', "%REACT_APP_MEASUREMENT_ID%");
</script>
也在我的 React.js 代码中
useEffect(() => {
ReactGA.initialize([{
trackingId: apiConsts.REACT_MEASUREMENT_ID,
testMode: apiConsts.DEV
}]);
}, [])
useEffect(() => {
ReactGA.send({ hitType: "pageview", page: location?.pathname + location?.search});
}, [location.pathname])
大约需要 24 至 48 小时才能反映在仪表板上!