diff --git a/helpers/handlePageRender.jsx b/helpers/handlePageRender.jsx index 206303c4..22def9ec 100644 --- a/helpers/handlePageRender.jsx +++ b/helpers/handlePageRender.jsx @@ -4,7 +4,7 @@ import { createStore } from 'redux'; import Reducer from '../react/reducers'; import { Provider } from 'react-redux'; import { StaticRouter } from 'react-router-dom'; -import GAListener from '../react/components/GAListener'; +import GAListener from '../react/containers/GAListener'; import App from '../react/app'; import renderFullPage from './renderFullPage.js'; import Helmet from 'react-helmet'; diff --git a/helpers/handleShowRender.jsx b/helpers/handleShowRender.jsx index ac9e2d32..b03b0306 100644 --- a/helpers/handleShowRender.jsx +++ b/helpers/handleShowRender.jsx @@ -4,7 +4,7 @@ import { createStore, applyMiddleware } from 'redux'; import Reducer from '../react/reducers'; import { Provider } from 'react-redux'; import { StaticRouter } from 'react-router-dom'; -import GAListener from '../react/components/GAListener'; +import GAListener from '../react/containers/GAListener'; import App from '../react/app'; import renderFullPage from './renderFullPage'; import createSagaMiddleware from 'redux-saga'; diff --git a/react/client.js b/react/client.js index bcd817fc..389a5ad8 100644 --- a/react/client.js +++ b/react/client.js @@ -7,7 +7,7 @@ import Reducer from 'reducers'; import createSagaMiddleware from 'redux-saga'; import rootSaga from 'sagas'; -import GAListener from 'components/GAListener'; +import GAListener from 'containers/GAListener'; import App from './app'; // get the state from a global variable injected into the server-generated HTML diff --git a/react/containers/GAListener/index.jsx b/react/containers/GAListener/index.jsx new file mode 100644 index 00000000..0f8f7405 --- /dev/null +++ b/react/containers/GAListener/index.jsx @@ -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); diff --git a/react/components/GAListener/index.jsx b/react/containers/GAListener/view.jsx similarity index 78% rename from react/components/GAListener/index.jsx rename to react/containers/GAListener/view.jsx index 6bcdd1e9..3b06c07e 100644 --- a/react/components/GAListener/index.jsx +++ b/react/containers/GAListener/view.jsx @@ -1,9 +1,6 @@ import React from 'react'; import GoogleAnalytics from 'react-ga'; import { withRouter } from 'react-router-dom'; -const {analytics: googleId} = require('../../../config/siteConfig.js'); - -GoogleAnalytics.initialize(googleId); class GAListener extends React.Component { componentDidMount () { @@ -17,6 +14,10 @@ class GAListener extends React.Component { } render () { + // initiate analytics + const { googleAnalyticsId } = this.props; + GoogleAnalytics.initialize(googleAnalyticsId); + // return children return this.props.children; } } diff --git a/react/reducers/site.js b/react/reducers/site.js index 08d1f6bf..0a1aeccf 100644 --- a/react/reducers/site.js +++ b/react/reducers/site.js @@ -1,11 +1,13 @@ const siteConfig = require('../../config/siteConfig.js'); const { - details: { title, host }, + analytics: { googleId: googleAnalyticsId }, assetDefaults: { thumbnail: defaultThumbnail }, + details: { title, host }, } = siteConfig; const initialState = { + googleAnalyticsId, host, title, defaults: {