diff --git a/helpers/handlebarsHelpers.js b/helpers/handlebarsHelpers.js index d660a600..5e857070 100644 --- a/helpers/handlebarsHelpers.js +++ b/helpers/handlebarsHelpers.js @@ -1,5 +1,5 @@ const Handlebars = require('handlebars'); -const { site, analytics, claim: claimDefaults } = require('../config/speechConfig.js'); +const { site, claim: claimDefaults } = require('../config/speechConfig.js'); function determineOgTitle (storedTitle, defaultTitle) { return ifEmptyReturnOther(storedTitle, defaultTitle); @@ -63,16 +63,6 @@ module.exports = { const headerBoilerplate = `${site.title}`; return new Handlebars.SafeString(headerBoilerplate); }, - googleAnalytics () { - const googleApiKey = analytics.googleId; - const gaCode = ``; - return new Handlebars.SafeString(gaCode); - }, addOpenGraph (claim) { const { ogTitle, ogDescription, showUrl, source, ogThumbnailContentType } = createOpenGraphDataFromClaim(claim, claimDefaults.defaultTitle, claimDefaults.defaultDescription); const thumbnail = claim.thumbnail; @@ -120,28 +110,4 @@ module.exports = { return new Handlebars.SafeString(`${basicTwitterTags} ${twitterCard}`); } }, - ifConditional (varOne, operator, varTwo, options) { - switch (operator) { - case '===': - return (varOne === varTwo) ? options.fn(this) : options.inverse(this); - case '!==': - return (varOne !== varTwo) ? options.fn(this) : options.inverse(this); - case '<': - return (varOne < varTwo) ? options.fn(this) : options.inverse(this); - case '<=': - return (varOne <= varTwo) ? options.fn(this) : options.inverse(this); - case '>': - return (varOne > varTwo) ? options.fn(this) : options.inverse(this); - case '>=': - return (varOne >= varTwo) ? options.fn(this) : options.inverse(this); - case '&&': - return (varOne && varTwo) ? options.fn(this) : options.inverse(this); - case '||': - return (varOne || varTwo) ? options.fn(this) : options.inverse(this); - case 'mod3': - return ((parseInt(varOne) % 3) === 0) ? options.fn(this) : options.inverse(this); - default: - return options.inverse(this); - } - }, }; diff --git a/package.json b/package.json index 55bf9ddd..96861b3f 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "prop-types": "^15.6.0", "react": "^16.2.0", "react-dom": "^16.2.0", + "react-ga": "^2.4.1", "react-redux": "^5.0.6", "react-router-dom": "^4.2.2", "redux": "^3.7.2", diff --git a/react/components/GAListener/index.js b/react/components/GAListener/index.js new file mode 100644 index 00000000..f388e2a0 --- /dev/null +++ b/react/components/GAListener/index.js @@ -0,0 +1,25 @@ +import React from 'react'; +import GoogleAnalytics from 'react-ga'; +import { withRouter } from 'react-router-dom'; +const config = require('../../../config/speechConfig.js'); +const googleApiKey = config.analytics.googleId; + +GoogleAnalytics.initialize(googleApiKey); + +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); diff --git a/react/root.js b/react/root.js index 86c1f53d..c4350ea9 100644 --- a/react/root.js +++ b/react/root.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import { Provider } from 'react-redux'; import { BrowserRouter, Route, Switch } from 'react-router-dom'; +import GAListener from 'components/GAListener'; import PublishPage from 'components/PublishPage'; import AboutPage from 'components/AboutPage'; import LoginPage from 'containers/LoginPage'; @@ -12,14 +13,16 @@ import FourOhFourPage from 'components/FourOhFourPage'; const Root = ({ store }) => ( - - - - - - - - + + + + + + + + + + ); diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars index 09068747..18122a33 100644 --- a/views/layouts/main.handlebars +++ b/views/layouts/main.handlebars @@ -12,8 +12,6 @@ - - {{ googleAnalytics }} {{{ body }}} diff --git a/views/layouts/showlite.handlebars b/views/layouts/showlite.handlebars deleted file mode 100644 index 632e1a83..00000000 --- a/views/layouts/showlite.handlebars +++ /dev/null @@ -1,18 +0,0 @@ - - - - {{ placeCommonHeaderTags }} - - {{#unless claimInfo.nsfw}} - {{{addTwitterCard claimInfo }}} - {{{addOpenGraph claimInfo }}} - {{/unless}} - - {{ googleAnalytics }} - - - - {{{ body }}} - - -