向reactJs应用程序添加GA
我正在尝试添加GA来记录页面点击率。我已经尝试了各种解决方案,但没有取得任何进展 在index.js中向reactJs应用程序添加GA,reactjs,google-analytics,Reactjs,Google Analytics,我正在尝试添加GA来记录页面点击率。我已经尝试了各种解决方案,但没有取得任何进展 在index.js中 import ReactGA from 'react-ga'; const hist = createBrowserHistory(); ReactGA.initialize('Tracking_Id'); hist.listen(location => { ReactGA.set({ page: location.pathname }); // Update the user'
import ReactGA from 'react-ga';
const hist = createBrowserHistory();
ReactGA.initialize('Tracking_Id');
hist.listen(location => {
ReactGA.set({ page: location.pathname }); // Update the user's current page
ReactGA.pageview(location.pathname + location.search); // Record a pageview for the given page
console.log(location.pathname)
});
我的路线是
<Provider store={store}>
<Router history={hist}>
<Route path='/thank-you' component={ThankYou} />
<Route path='/auth' component={AuthLayout} />
<Route exact path='/' component={HomeLayout} />
<Switch>
<PrivateRoute path='/admin' component={AdminLayout} />
</Switch>
</Router>
</Provider>,
,
请告诉我我做错了什么。根据您的评论,这取决于您使用的是Google Analytics 4属性ID(G-XXXXXXXX),而有问题的React Analytics软件包适用于Universal Analytics。我建议您创建一个Universal Analytics属性(如下图所示),并使用相对标识符UA-XXXXXXX-X:
怎么了?我调试了它,它工作正常,但我没有收到谷歌分析上的数据。你的跟踪id的格式是“G-XXXXXX”或“UA-XXXXX-XX”?G-XXXXXX是格式让我试试看是的,让我知道:)