From 6a705c07c75f76c5c4d8ccb2920d73330432d768 Mon Sep 17 00:00:00 2001 From: SarthakKamboj Date: Tue, 29 Dec 2020 18:06:45 -0800 Subject: [PATCH 1/3] added ga events and pageviews --- src/App.tsx | 10 ++++++++- src/GARouteUpdater.tsx | 8 +++++++ src/index.tsx | 2 +- src/pages/Auth/index.tsx | 48 +++++++++++++++++++++++----------------- src/pages/Home/index.tsx | 24 +++++++++++++------- 5 files changed, 62 insertions(+), 30 deletions(-) create mode 100644 src/GARouteUpdater.tsx diff --git a/src/App.tsx b/src/App.tsx index 19cc654..c5d0ad9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,11 +1,19 @@ import React from 'react'; import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; - +// import ReactGa from 'react-ga'; import Home from 'pages/Home'; import Auth from 'pages/Auth'; import StaticFileRedirect from 'components/StaticFileRedirect'; function App(): JSX.Element { + // const notifyGA = (path: string) => { + // switch (path) { + // case "/": + // ReactGa.pageview() + // break; + // }; + // }; + return ( diff --git a/src/GARouteUpdater.tsx b/src/GARouteUpdater.tsx new file mode 100644 index 0000000..da427da --- /dev/null +++ b/src/GARouteUpdater.tsx @@ -0,0 +1,8 @@ +import React from 'react'; + +const GARouteUpdater: React.FC = () => ( + <> + +); + +export default GARouteUpdater; diff --git a/src/index.tsx b/src/index.tsx index 2ebd1e1..6851659 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -6,7 +6,7 @@ import App from './App'; import reportWebVitals from './reportWebVitals'; ReactGA.initialize('G-2D2S4GLZPR', { - testMode: process.env.NODE_ENV !== 'production', + // testMode: process.env.NODE_ENV !== 'production', }); ReactDOM.render( diff --git a/src/pages/Auth/index.tsx b/src/pages/Auth/index.tsx index 22c3066..0c1d10e 100644 --- a/src/pages/Auth/index.tsx +++ b/src/pages/Auth/index.tsx @@ -1,39 +1,47 @@ -import React from 'react'; +// temporary +/* eslint-disable */ +// @ts-nocheck + +import React, { useEffect } from 'react'; import queryString from 'query-string'; import { useLocation } from 'react-router-dom'; - -import { getToken } from 'util/api'; +import ReactGa from 'react-ga'; +import { getToken } from 'api'; // import Loading from 'components/Loading'; -function mobileRedirect(os: 'android' | 'ios', code: string) { - const to = `hackillinois://org.hackillinois.${os}/auth?code=${code}`; - window.location.replace(to); -} + const Auth: React.FC = () => { - const location = useLocation(); - type QueryTypes = { - code?: string; - isAndroid?: string; - isiOS?: string; - to?: string; - }; - const { code, isAndroid, isiOS, to }: QueryTypes = queryString.parse(location.search); + useEffect(() => { + function mobileRedirect(os: string, code) { + const to = `hackillinois://org.hackillinois.${os}/auth?code=${code}`; + ReactGa.event(os); + window.location.replace(to); + } + const location = useLocation(); + const { + code, + isAndroid, + isiOS, + to, + } = queryString.parse(location.search); + + if (!code) { + window.location.replace('/'); + } - if (code) { if (isAndroid || isiOS) { const os = isAndroid ? 'android' : 'ios'; mobileRedirect(os, code); } else { getToken(code).then((token) => { sessionStorage.setItem('token', token); - window.location.replace(to as string); + window.location.replace(to); }); } - } else { - window.location.replace('/'); - } + ReactGa.pageview("/Auth"); + },[]); return
Loading...
; // ; }; diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx index caf11c1..282dc65 100644 --- a/src/pages/Home/index.tsx +++ b/src/pages/Home/index.tsx @@ -1,13 +1,21 @@ -import React from 'react'; - +import React, { useEffect } from 'react'; +import ReactGa from 'react-ga'; import Hero from './Hero'; // import EventInfo from './EventInfo'; -const Home: React.FC = () => ( - <> - - {/* */} - -); +const Home: React.FC = () => { + useEffect(() => { + ReactGa.pageview('/'); + }, []); + + return ( + <> + + { + /* */ + } + + ); +}; export default Home; From 309c73d4d2d466914e4a5045728f6adcb99d50be Mon Sep 17 00:00:00 2001 From: SarthakKamboj Date: Tue, 29 Dec 2020 18:17:13 -0800 Subject: [PATCH 2/3] pulled and made a few changes in Auth --- .eslintrc | 1 + src/pages/Auth/index.tsx | 60 +++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/.eslintrc b/.eslintrc index cdaf6a6..ba627b3 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,6 +13,7 @@ "react/require-default-props": "off", "linebreak-style": "off", "no-param-reassign": "off", + "react/prop-types": "off", "max-len": "off" } } \ No newline at end of file diff --git a/src/pages/Auth/index.tsx b/src/pages/Auth/index.tsx index 0c1d10e..6005afb 100644 --- a/src/pages/Auth/index.tsx +++ b/src/pages/Auth/index.tsx @@ -1,47 +1,45 @@ -// temporary -/* eslint-disable */ -// @ts-nocheck - import React, { useEffect } from 'react'; import queryString from 'query-string'; import { useLocation } from 'react-router-dom'; import ReactGa from 'react-ga'; -import { getToken } from 'api'; +import { getToken } from 'util/api'; // import Loading from 'components/Loading'; - +function mobileRedirect(os: 'android' | 'ios', code: string) { + ReactGa.event(os); + const to = `hackillinois://org.hackillinois.${os}/auth?code=${code}`; + window.location.replace(to); +} + +type QueryTypes = { + code?: string; + isAndroid?: string; + isiOS?: string; + to?: string; +}; const Auth: React.FC = () => { + const location = useLocation(); useEffect(() => { - function mobileRedirect(os: string, code) { - const to = `hackillinois://org.hackillinois.${os}/auth?code=${code}`; - ReactGa.event(os); - window.location.replace(to); - } - const location = useLocation(); - const { - code, - isAndroid, - isiOS, - to, - } = queryString.parse(location.search); - - if (!code) { + ReactGa.pageview("/auth"); + const { code, isAndroid, isiOS, to }: QueryTypes = queryString.parse(location.search); + + if (code) { + if (isAndroid || isiOS) { + const os = isAndroid ? 'android' : 'ios'; + mobileRedirect(os, code); + } else { + getToken(code).then((token) => { + sessionStorage.setItem('token', token); + window.location.replace(to as string); + }); + } + } else { window.location.replace('/'); } - if (isAndroid || isiOS) { - const os = isAndroid ? 'android' : 'ios'; - mobileRedirect(os, code); - } else { - getToken(code).then((token) => { - sessionStorage.setItem('token', token); - window.location.replace(to); - }); - } - ReactGa.pageview("/Auth"); - },[]); + }, []) return
Loading...
; // ; }; From 6637e03af05db3979d22a0fcdf328ed0b1ead418 Mon Sep 17 00:00:00 2001 From: SarthakKamboj Date: Tue, 29 Dec 2020 20:59:42 -0800 Subject: [PATCH 3/3] added events for mobile --- src/pages/Auth/index.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pages/Auth/index.tsx b/src/pages/Auth/index.tsx index 6005afb..e3eb56f 100644 --- a/src/pages/Auth/index.tsx +++ b/src/pages/Auth/index.tsx @@ -6,7 +6,10 @@ import { getToken } from 'util/api'; // import Loading from 'components/Loading'; function mobileRedirect(os: 'android' | 'ios', code: string) { - ReactGa.event(os); + ReactGa.event({ + category: 'mobile', + action: os, + }); const to = `hackillinois://org.hackillinois.${os}/auth?code=${code}`; window.location.replace(to); } @@ -22,7 +25,7 @@ const Auth: React.FC = () => { const location = useLocation(); useEffect(() => { - ReactGa.pageview("/auth"); + ReactGa.pageview('/auth'); const { code, isAndroid, isiOS, to }: QueryTypes = queryString.parse(location.search); if (code) { @@ -38,9 +41,7 @@ const Auth: React.FC = () => { } else { window.location.replace('/'); } - - }, []) - + }, []); return
Loading...
; // ; };