From 0d49d551b9528717f1ca98407a73ffeff005d1dc Mon Sep 17 00:00:00 2001 From: Luke Berndt Date: Tue, 14 Feb 2023 20:44:30 -0500 Subject: [PATCH] Add back Google Analytics --- frontend/public/index.html | 11 +++++++++++ frontend/src/app.js | 39 +++++++++++++++++++++++++++++++++++++ frontend/src/index.js | 38 +++++------------------------------- frontend/src/tracking.js | 15 ++++++++++++++ frontend/src/withTracker.js | 39 ------------------------------------- prod.env.example | 6 +----- 6 files changed, 71 insertions(+), 77 deletions(-) create mode 100644 frontend/src/app.js create mode 100644 frontend/src/tracking.js delete mode 100644 frontend/src/withTracker.js diff --git a/frontend/public/index.html b/frontend/public/index.html index cd503df..afcf9a1 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -27,7 +27,18 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> + %REACT_APP_SITE_NAME% + + diff --git a/frontend/src/app.js b/frontend/src/app.js new file mode 100644 index 0000000..99bd2fc --- /dev/null +++ b/frontend/src/app.js @@ -0,0 +1,39 @@ + + +import { Routes ,Route } from 'react-router-dom'; +import { usePageTracking } from "./tracking"; + +import 'semantic-ui-css/semantic.min.css' + +// Main +import Main from "./Main/Main" + +// System +import ListSystems from "./System/ListSystems" + +// Call +import Calls from "./Call/Calls" + +import AboutComponent from "./About/AboutComponent" + +// Event +import ListEvents from "./Event/ListEvents" +import ViewEvent from "./Event/ViewEvent" + + +const App = () => { +usePageTracking(); + +return ( + + } /> + } /> + } /> + } /> + } /> + } /> + +) +} + +export default App; \ No newline at end of file diff --git a/frontend/src/index.js b/frontend/src/index.js index 9790773..7581c52 100644 --- a/frontend/src/index.js +++ b/frontend/src/index.js @@ -1,30 +1,10 @@ import React from 'react'; import { createRoot } from 'react-dom/client'; -import { Routes ,Route } from 'react-router-dom'; import { BrowserRouter } from "react-router-dom"; import { Provider } from 'react-redux' -import configureStore, { history } from './redux-router/configureStore' +import configureStore from './redux-router/configureStore' -import 'semantic-ui-css/semantic.min.css' - -// withTracker -//import withTracker from './withTracker'; - -// Main -import Main from "./Main/Main" - -// System -import ListSystems from "./System/ListSystems" - -// Call -import Calls from "./Call/Calls" - -import AboutComponent from "./About/AboutComponent" - -// Event - -import ListEvents from "./Event/ListEvents" -import ViewEvent from "./Event/ViewEvent" +import App from "./app" const store = configureStore(/* provide initial state if any */) @@ -32,16 +12,8 @@ const container = document.getElementById('root'); const root = createRoot(container); root.render( - - - } /> - } /> - } /> - } /> - } /> - } /> - - - + + + ) \ No newline at end of file diff --git a/frontend/src/tracking.js b/frontend/src/tracking.js new file mode 100644 index 0000000..787cae1 --- /dev/null +++ b/frontend/src/tracking.js @@ -0,0 +1,15 @@ + +import { useEffect } from "react"; +import { useLocation } from "react-router-dom"; + +export const usePageTracking = () => { + const location = useLocation(); + + useEffect(() => { + window.gtag("event", "page_view", { + page_path: location.pathname + location.search + location.hash, + page_search: location.search, + page_hash: location.hash, + }); + }, [location]); +}; \ No newline at end of file diff --git a/frontend/src/withTracker.js b/frontend/src/withTracker.js deleted file mode 100644 index ffef390..0000000 --- a/frontend/src/withTracker.js +++ /dev/null @@ -1,39 +0,0 @@ -import React, { Component } from 'react'; -import ReactGA from 'react-ga'; - -export default function withTracker(WrappedComponent, options = {}) { - const trackPage = (page) => { - ReactGA.set({ - page, - ...options - }); - ReactGA.pageview(page); - }; - - const HOC = class extends Component { - componentDidMount() { - const { - location: { pathname: page } - } = this.props; - trackPage(page); - } - - // eslint-disable-next-line camelcase - UNSAFE_componentWillReceiveProps(nextProps) { - const { - location: { pathname: currentPage } - } = this.props; - const nextPage = nextProps.location.pathname; - - if (currentPage !== nextPage) { - trackPage(nextPage); - } - } - - render() { - return ; - } - }; - - return HOC; -} \ No newline at end of file diff --git a/prod.env.example b/prod.env.example index 139a9fe..bf4bdee 100644 --- a/prod.env.example +++ b/prod.env.example @@ -21,10 +21,6 @@ export REACT_APP_SOCKET_SERVER=wss://socket.${DOMAIN_NAME} export REACT_APP_ACCOUNT_SERVER="${PROTOCOL}account.${DOMAIN_NAME}" export REACT_APP_ADMIN_SERVER="${PROTOCOL}admin.${DOMAIN_NAME}" export REACT_APP_COOKIE_DOMAIN=".${DOMAIN_NAME}" - -export TWITTER_CONSUMER_KEY="" -export TWITTER_CONSUMER_SECRET="" -export TWITTER_ACCESS_TOKEN_KEY="" -export TWITTER_ACCESS_TOKEN_SECRET="" +export REACT_APP_GOOGLE_ANALYTICS=""