moved GA listing events to component did mount

This commit is contained in:
bill bittner 2018-03-15 15:17:17 -07:00
parent 3ff70c4f9d
commit c4ccc9a361
5 changed files with 11 additions and 12 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -4,8 +4,13 @@ import { withRouter } from 'react-router-dom';
class GAListener extends React.Component {
componentDidMount () {
this.sendPageView(this.props.history.location);
this.props.history.listen(this.sendPageView);
// 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) {
@ -14,12 +19,6 @@ class GAListener extends React.Component {
}
render () {
// initiate analytics
const { googleAnalyticsId } = this.props;
if (googleAnalyticsId) {
GoogleAnalytics.initialize(googleAnalyticsId);
}
// return children
return this.props.children;
}
}