Skip to content

Commit

Permalink
Merge branch 'master' into 593-google-analytics-not-displaying-page-s…
Browse files Browse the repository at this point in the history
…pecific-hits
  • Loading branch information
nicoalee authored Aug 7, 2024
2 parents 7e3a542 + a19dd3f commit 419b878
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 3 additions & 5 deletions compose/neurosynth-frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-0L9Y0HT9NR"></script>
<script type="text/javascript">
// if (document.location.hostname === "compose.neurosynth.org") {
if (document.location.hostname === "compose.neurosynth.org") {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-0L9Y0HT9NR', {
'send_page_view': false
});
// }
gtag('config', 'G-0L9Y0HT9NR');
}
</script>

<!-- Appzi: Capture Insightful Feedback -->
Expand Down
12 changes: 11 additions & 1 deletion compose/neurosynth-frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { IconButton } from '@mui/material';
import { AxiosError } from 'axios';
import useGoogleAnalytics from 'hooks/useGoogleAnalytics';
import { SnackbarKey, SnackbarProvider } from 'notistack';
import { useRef } from 'react';
import { useEffect, useRef } from 'react';
import { QueryCache, QueryClient, QueryClientProvider } from 'react-query';
import Navbar from './components/Navbar/Navbar';
import useGetToken from './hooks/useGetToken';
import BaseNavigation from './pages/BaseNavigation/BaseNavigation';
import { useLocation } from 'react-router-dom';

const queryClient = new QueryClient({
defaultOptions: {
Expand Down Expand Up @@ -42,6 +43,15 @@ function App() {
useGetToken();
useGoogleAnalytics();

const location = useLocation();
useEffect(() => {
if (window.gtag) {
window.gtag('event', 'page_view', {
page_path: `${location.pathname}${location.search}`,
});
}
}, [location]);

const handleCloseSnackbar = (key: SnackbarKey) => (_event: React.MouseEvent) => {
if (notistackRef?.current?.closeSnackbar) notistackRef.current?.closeSnackbar(key);
};
Expand Down

0 comments on commit 419b878

Please sign in to comment.