Skip to content

Commit a19dd3f

Browse files
authored
feat: update gtags (#805)
1 parent 08e15f2 commit a19dd3f

File tree

5 files changed

+39
-14
lines changed

5 files changed

+39
-14
lines changed

compose/neurosynth-frontend/public/index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@
2626
/>
2727
<!-- Google tag (gtag.js) -->
2828
<script async src="https://www.googletagmanager.com/gtag/js?id=G-0L9Y0HT9NR"></script>
29-
<script>
30-
window.dataLayer = window.dataLayer || [];
31-
function gtag(){dataLayer.push(arguments);}
32-
gtag('js', new Date());
33-
34-
gtag('config', 'G-0L9Y0HT9NR');
29+
<script type="text/javascript">
30+
if (document.location.hostname === "compose.neurosynth.org") {
31+
window.dataLayer = window.dataLayer || [];
32+
function gtag(){dataLayer.push(arguments);}
33+
gtag('js', new Date());
34+
gtag('config', 'G-0L9Y0HT9NR');
35+
}
36+
</script>
3537

38+
<!-- Appzi: Capture Insightful Feedback -->
39+
<script async src="https://w.appzi.io/w.js?token=jFjBf">
3640
window.appziSettings = {
3741
render: { type: 'client' }
3842
}
3943
</script>
4044

41-
<!-- Appzi: Capture Insightful Feedback -->
42-
43-
<script async src="https://w.appzi.io/w.js?token=jFjBf"></script>
44-
4545
<!-- End Appzi -->
4646

4747
<!--

compose/neurosynth-frontend/src/App.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import Close from '@mui/icons-material/Close';
22
import { IconButton } from '@mui/material';
33
import { AxiosError } from 'axios';
44
import { SnackbarKey, SnackbarProvider } from 'notistack';
5-
import { useRef } from 'react';
5+
import { useEffect, useRef } from 'react';
66
import { QueryCache, QueryClient, QueryClientProvider } from 'react-query';
77
import Navbar from './components/Navbar/Navbar';
88
import useGetToken from './hooks/useGetToken';
99
import BaseNavigation from './pages/BaseNavigation/BaseNavigation';
10+
import { useLocation } from 'react-router-dom';
1011

1112
const queryClient = new QueryClient({
1213
defaultOptions: {
@@ -26,10 +27,29 @@ const queryClient = new QueryClient({
2627
}),
2728
});
2829

30+
declare global {
31+
interface Window {
32+
gtag?: (
33+
type: 'event' | 'config' | 'get' | 'set' | 'consent',
34+
action: 'login' | 'page_view',
35+
options?: any
36+
) => void;
37+
}
38+
}
39+
2940
function App() {
3041
const notistackRef = useRef<SnackbarProvider>(null);
3142
useGetToken();
3243

44+
const location = useLocation();
45+
useEffect(() => {
46+
if (window.gtag) {
47+
window.gtag('event', 'page_view', {
48+
page_path: `${location.pathname}${location.search}`,
49+
});
50+
}
51+
}, [location]);
52+
3353
const handleCloseSnackbar = (key: SnackbarKey) => (_event: React.MouseEvent) => {
3454
if (notistackRef?.current?.closeSnackbar) notistackRef.current?.closeSnackbar(key);
3555
};

compose/neurosynth-frontend/src/components/Navbar/Navbar.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const Navbar: React.FC = (_props) => {
2121
audience: AUTH0_AUDIENCE,
2222
scope: 'openid profile email offline_access',
2323
});
24+
25+
if (window.gtag) {
26+
window.gtag('event', 'login');
27+
}
28+
2429
navigate('/');
2530
};
2631

compose/neurosynth-frontend/src/pages/BaseNavigation/components/ProtectedMetaAnalysesRoute.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ const ProtectedMetaAnalysesRoute: React.FC<{
1717
const { pathname } = useLocation();
1818
const userCanEdit = useUserCanEdit(project?.user ?? undefined);
1919

20-
console.log('HELLOOooooooo');
21-
console.log(project?.public);
22-
2320
const isOk = userCanEdit || project?.public;
2421

2522
if (getProjectIsLoading || getMetaAnalysisIsLoading || getAuthIsLoading) {

compose/neurosynth-frontend/src/pages/LandingPage/LandingPage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const LandingPage = () => {
2424
audience: AUTH0_AUDIENCE,
2525
scope: 'openid profile email offline_access',
2626
});
27+
if (window.gtag) {
28+
window.gtag('event', 'login');
29+
}
2730
navigate('/');
2831
};
2932

0 commit comments

Comments
 (0)