【发布时间】:2018-08-30 02:26:58
【问题描述】:
我在 github 页面上托管了我的作品集(仍在开发中)。它只是一个具有静态内容的网络应用程序。我需要将 Google Analytics 添加到我的投资组合中并获取访问次数(主要是为了熟悉流程)。我发现 react-ga 模块可用于在 React Apps(使用 create-react-app 创建)上配置 Google Analytics。
并按照this 教程进行配置和托管。我用测试流量检查了该网站,但 Google Analytics(分析)仪表板没有更新。可能是什么情况?它应该按照教程工作。由于我是 Google Analytics 的新手,我很难找出问题所在。
这是我的 App.js
import React, { Component } from "react";
import HeaderList from "./components/Header";
import "./App.css";
import { Layout } from "antd";
import { Router, Route, Switch } from "react-router-dom";
import createHistory from "history/createBrowserHistory";
import ReactGA from 'react-ga';
import Keys from './config/keys';
import AboutMe from "./components/AboutMe";
import Skills from "./components/Skills";
import Contact from "./components/Contact";
import Projects from "./components/Projects";
const { Content } = Layout;
ReactGA.initialize(Keys.GOOGLE_TRACKING_ID); //Unique Google Analytics tracking number
function fireTracking() {
ReactGA.pageview(window.location.hash);
}
class App extends Component {
render() {
return (
<Router onUpdate={fireTracking} history={createHistory({ basename: process.env.PUBLIC_URL })}>
<div>
<Layout>
<HeaderList />
<Content className="Content">
<div className="RouteContent">
<Switch>
<Route exact path="/" component={AboutMe} />
<Route path="/skills" component={Skills} />
<Route path="/projects" component={Projects} />
<Route path="/Contact" component={Contact} />
</Switch>
</div>
</Content>
</Layout>
</div>
</Router>
);
}
}
export default App;
【问题讨论】:
-
你用的是什么版本的 react-router?
-
第 4 版。
"react-router-dom": "^4.2.2" -
@ztadic91 你为什么删除你发布的答案?关于这个问题的任何帮助?
标签: reactjs google-analytics react-router create-react-app react-router-dom