Upgrade to gtag

This commit is contained in:
Nicholas Zuber 2019-12-08 22:46:45 -05:00
parent 561d0dcb4a
commit 08acf46f97
2 changed files with 22 additions and 4 deletions

View File

@ -1,6 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-154218045-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-154218045-1');
</script>
<meta charset="utf-8">
<link rel="shortcut icon" href="%PUBLIC_URL%/iconCircle.png">
<link rel="apple-touch-icon" sizes="180x180" href="%PUBLIC_URL%/new-app-icon.png">

View File

@ -4,7 +4,6 @@ import {
Location,
LocationProvider
} from "@reach/router";
import ReactGA from 'react-ga';
import { routes } from './constants';
import { AuthProvider } from './providers/Auth';
import {
@ -16,13 +15,24 @@ import {
NotificationsRedesign,
} from './pages';
// Initialize Google Analytics.
ReactGA.initialize('UA-154218045-1');
// @TODO: abstract further once confirmed this works.
function gtag () {
window.dataLayer = window.dataLayer || [];
return () => {
window.dataLayer.push(arguments);
};
}
function gaTrack (options) {
gtag('config', 'UA-154218045-1', options);
}
// Effectively track each new page.
function PageTracker ({location}) {
React.useEffect(() => {
ReactGA.pageview(location.pathname);
gaTrack({
page_location: location,
page_path: location.pathname
});
}, [location]);
return null;