moved google analytics id to state

This commit is contained in:
bill bittner 2018-03-15 11:02:23 -07:00
parent 7238448a90
commit e3279ed414
6 changed files with 20 additions and 7 deletions

View file

@ -4,7 +4,7 @@ import { createStore } from 'redux';
import Reducer from '../react/reducers'; import Reducer from '../react/reducers';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { StaticRouter } from 'react-router-dom'; import { StaticRouter } from 'react-router-dom';
import GAListener from '../react/components/GAListener'; import GAListener from '../react/containers/GAListener';
import App from '../react/app'; import App from '../react/app';
import renderFullPage from './renderFullPage.js'; import renderFullPage from './renderFullPage.js';
import Helmet from 'react-helmet'; import Helmet from 'react-helmet';

View file

@ -4,7 +4,7 @@ import { createStore, applyMiddleware } from 'redux';
import Reducer from '../react/reducers'; import Reducer from '../react/reducers';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { StaticRouter } from 'react-router-dom'; import { StaticRouter } from 'react-router-dom';
import GAListener from '../react/components/GAListener'; import GAListener from '../react/containers/GAListener';
import App from '../react/app'; import App from '../react/app';
import renderFullPage from './renderFullPage'; import renderFullPage from './renderFullPage';
import createSagaMiddleware from 'redux-saga'; import createSagaMiddleware from 'redux-saga';

View file

@ -7,7 +7,7 @@ import Reducer from 'reducers';
import createSagaMiddleware from 'redux-saga'; import createSagaMiddleware from 'redux-saga';
import rootSaga from 'sagas'; import rootSaga from 'sagas';
import GAListener from 'components/GAListener'; import GAListener from 'containers/GAListener';
import App from './app'; import App from './app';
// get the state from a global variable injected into the server-generated HTML // get the state from a global variable injected into the server-generated HTML

View file

@ -0,0 +1,10 @@
import { connect } from 'react-redux';
import View from './view';
const mapStateToProps = ({ site: { googleAnalyticsId } }) => {
return {
googleAnalyticsId,
};
};
export default connect(mapStateToProps, null)(View);

View file

@ -1,9 +1,6 @@
import React from 'react'; import React from 'react';
import GoogleAnalytics from 'react-ga'; import GoogleAnalytics from 'react-ga';
import { withRouter } from 'react-router-dom'; import { withRouter } from 'react-router-dom';
const {analytics: googleId} = require('../../../config/siteConfig.js');
GoogleAnalytics.initialize(googleId);
class GAListener extends React.Component { class GAListener extends React.Component {
componentDidMount () { componentDidMount () {
@ -17,6 +14,10 @@ class GAListener extends React.Component {
} }
render () { render () {
// initiate analytics
const { googleAnalyticsId } = this.props;
GoogleAnalytics.initialize(googleAnalyticsId);
// return children
return this.props.children; return this.props.children;
} }
} }

View file

@ -1,11 +1,13 @@
const siteConfig = require('../../config/siteConfig.js'); const siteConfig = require('../../config/siteConfig.js');
const { const {
details: { title, host }, analytics: { googleId: googleAnalyticsId },
assetDefaults: { thumbnail: defaultThumbnail }, assetDefaults: { thumbnail: defaultThumbnail },
details: { title, host },
} = siteConfig; } = siteConfig;
const initialState = { const initialState = {
googleAnalyticsId,
host, host,
title, title,
defaults: { defaults: {