我正在尝试将react-ga添加到 Rails 5 API 和 React-Redux 应用程序。我已按照文档中概述的步骤进行操作,启用调试模式后,事件会记录在控制台中,但 Google Analytics(分析)未收到任何跟踪信息。我很好奇这里是否有人对潜在问题有任何想法。我的 index.js 文件包含在下面 - 请注意,我在此处发布之前从代码中删除了我的实际 UID。谢谢!
客户端/src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { Router, browserHistory } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux'
import configureStore from './store/configureStore';
import routes from './routes';
import ReactGA from 'react-ga';
const store = configureStore();
const history = syncHistoryWithStore(browserHistory, store)
export default history;
ReactGA.initialize('MY_UID', {
debug: true,
});
function logPageView() {
ReactGA.set({ page: window.location.pathname });
ReactGA.pageview(window.location.pathname);
}
ReactDOM.render(
<Provider store={store}>
<Router routes={routes} history={history} onUpdate={logPageView}/>
</Provider>,
document.getElementById('root')
);