Eri*_*Lee 5 javascript google-analytics reactjs react-ga
我已经构建了一个 React Web 应用程序,我想使用 Google Analytics 跟踪用户在我的网站上花费的时间。
目前我正在使用react-ga(https://github.com/react-ga/react-ga)作为将 Google Analytics 与 React 绑定的工具。我已经使用 Google Analytics 成功跟踪了每个页面。我可以像这样看到流量来源和概述:
Google Analytics Screen shot
然而,当我检查平均数时。“花费时间”页面:Google Analytics 行为概述。我看不到任何关于 avg 的数据。所花费的时间。
以下是我在代码中设置的内容,我在 App.js 文件中初始化了 ReactGA:
应用程序.js
componentDidMount() {
ReactGA.initialize('UA-xxxxxxx-x')
....
}
Run Code Online (Sandbox Code Playgroud)
我在 Routing.js 文件中跟踪了我的页面,其中我的所有反应路由器路由都在此文件中:
路由.js
componentDidMount() {
this.props.history.listen(location => ReactGA.pageview(location.pathname))
...
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,这就是我为 Google Analytics 设置的全部内容react-ga。
我是否错过了跟踪平均数的任何内容?在我的网站上花费的时间?
小智 0
您可以使用计时 api:允许通过使用analytics.js 库发送命中来测量时间段,例如 AJAX 请求和资源加载。
ReactGA.timing({
category: 'JS Libraries',
variable: 'load',
value: 20, // in milliseconds
label: 'CDN libs'
});
Run Code Online (Sandbox Code Playgroud)
这相当于以下 Google Analytics 命令:
ga('send', 'timing', 'JS Libraries', 'load', 20, 'CDN libs');
Run Code Online (Sandbox Code Playgroud)
https://developers.google.com/analytics/devguides/collection/analyticsjs/user-timings
| 归档时间: |
|
| 查看次数: |
1803 次 |
| 最近记录: |