reverted GA component

This commit is contained in:
bill bittner 2018-03-15 15:35:58 -07:00
parent c4ccc9a361
commit 0aa78efa5d
6 changed files with 58841 additions and 43 deletions
index.js
public/bundle
react
components/SEO
containers
FourOhFourPage
GAListener

10961
index.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import NavBar from 'containers/NavBar/index'; import NavBar from 'containers/NavBar';
import Helmet from 'react-helmet'; import Helmet from 'react-helmet';
class FourOhForPage extends React.Component { class FourOhForPage extends React.Component {

View file

@ -1,10 +1,23 @@
import { connect } from 'react-redux'; import React from 'react';
import View from './view'; import GoogleAnalytics from 'react-ga';
import { withRouter } from 'react-router-dom';
const mapStateToProps = ({ site: { googleAnalyticsId } }) => { GoogleAnalytics.initialize('test');
return {
googleAnalyticsId,
};
};
export default connect(mapStateToProps, null)(View); class GAListener extends React.Component {
componentDidMount () {
this.sendPageView(this.props.history.location);
this.props.history.listen(this.sendPageView);
}
sendPageView (location) {
GoogleAnalytics.set({ page: location.pathname });
GoogleAnalytics.pageview(location.pathname);
}
render () {
return this.props.children;
}
}
export default withRouter(GAListener);

View file

@ -1,26 +0,0 @@
import React from 'react';
import GoogleAnalytics from 'react-ga';
import { withRouter } from 'react-router-dom';
class GAListener extends React.Component {
componentDidMount () {
// initiate analytics
const { googleAnalyticsId } = this.props;
if (googleAnalyticsId) {
GoogleAnalytics.initialize(googleAnalyticsId);
this.sendPageView(this.props.history.location);
this.props.history.listen(this.sendPageView);
}
}
sendPageView (location) {
GoogleAnalytics.set({ page: location.pathname });
GoogleAnalytics.pageview(location.pathname);
}
render () {
return this.props.children;
}
}
export default withRouter(GAListener);