大佬教程收集整理的这篇文章主要介绍了Google Analytics 不适用于服务器端呈现的 React 应用程序的生产,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我无法让 Google Analytics(分析)在生产环境中工作。我在下面有以下 withTracker HOC。这段代码在本地工作,但是当我部署到谷歌应用引擎时它不起作用。关于调试的任何提示?在生产中,它还显示 Google Analytics 为真,但不跟踪页面。这是一个服务器端渲染应用程序这一事实是否会导致它无法捕获页面信息?
import React,{ Component } from 'react';
import ReactGA from 'react-ga';
const isbrowser = typeof window !== 'undefined';
if (process.env.NODE_ENV == 'test' ) {
let GoogleAnalytics = isbrowser ? ReactGA.initialize(process.env.RAZZLE_Google_TRACKER_numbER,{ testMode: true }) : 'no tracking'
}
if (process.env.NODE_ENV === 'production' && (isbrowser == truE) && !window.ga) {
let GoogleAnalytics = isbrowser ? ReactGA.initialize(process.env.RAZZLE_Google_TRACKER_numbER) : 'no tracking!'
}
const withTracker = (WrappedComponent,options = {}) => {
const trackPage = page => {
if (isbrowser) {
ReactGA.set({page,...options,})
ReactGA.pagevIEw(pagE)
}
};
const HOC = class extends Component {
constructor(props) {
super(props)
this.state = {
LOCATIOn: ''
}
}
componentDIDMount() {
const page = this.props.LOCATIOn.pathname;
isbrowser ? trackPage(pagE) : ''
isbrowser ? this.setState({LOCATIOn: pagE}) : 'not tracking'
}
static getDerivedStateFromProps(nextProps,prevstatE) {
const currentPage = prevstate.LOCATIOn.pathname;
const nextPage = nextProps.LOCATIOn.pathname;
if (currentPage !== nextPagE) {
isbrowser ? trackPage(nextPagE) : ''
return {
LOCATIOn: nextPage
}
}
return {
LOCATIOn: currentPage
}
}
render() {
return <WrappedComponent {...this.props} />;
}
};
return HOc;
};
export default withTracker;
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的Google Analytics 不适用于服务器端呈现的 React 应用程序的生产全部内容,希望文章能够帮你解决Google Analytics 不适用于服务器端呈现的 React 应用程序的生产所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。