在react-admin应用上使用GA的最好、最简单的方法是什么?
我知道npm模块react-ga,但它只跟踪主页:
import ReactGA from 'react-ga';
ReactGA.initialize('UA-12345');
ReactGA.pageview(window.location.pathname + window.location.search);有没有什么通用的方法来查看每个资源页面和每个操作的页面视图?
发布于 2020-03-15 06:33:28
通过使用自定义历史记录,我能够让它正常工作。
import { createBrowserHistory } from 'history';
import ReactGA from 'react-ga';
// create the history
const history = createBrowserHistory();
// listen for a route change and record page view
history.listen(location => {
ReactGA.pageview(location.pathname);
});
// initialize GA
ReactGA.initialize('UA-000000000-1');
// record the first pageview because listen will not be called
ReactGA.pageview(window.location.pathname);带有历史包的listen文档:https://github.com/ReactTraining/history/blob/master/docs/GettingStarted.md#listening
不要忘记在您的Admin组件中连接您的客户历史记录:
<Admin
history={history}
>
...
</Admin>有关详细信息,请参阅https://marmelab.com/admin-on-rest/Admin.html#history
https://stackoverflow.com/questions/56315758
复制相似问题