Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log page_view event #73

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,893 changes: 1,893 additions & 0 deletions react-ui/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions react-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"clsx": "^1.1.1",
"cross-env": "^7.0.3",
"date-fns": "^2.16.1",
"firebase": "^9.6.10",
"lodash": "^4.17.21",
"prop-types": "^15.7.2",
"react": "^17.0.1",
Expand Down
2 changes: 2 additions & 0 deletions react-ui/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SWRConfig } from 'swr';

import { getData } from './api';
import { DrawerStateContext } from './common';
import { Analytics } from './components';
import {
Contest, Contests, Entry, HallOfFame, Home,
} from './pages';
Expand Down Expand Up @@ -39,6 +40,7 @@ const App = () => {
<DrawerStateContext.Provider value={drawerStateContextValue}>
<div className="app">
<Router>
<Analytics />
<Route exact path="/">
<Redirect to="/home" />
</Route>
Expand Down
17 changes: 17 additions & 0 deletions react-ui/src/common/firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getAnalytics } from 'firebase/analytics';
import { initializeApp } from 'firebase/app';

const firebaseConfig = {
apiKey: 'AIzaSyAV96xMFqykyH9HULiAG4qkx9bB53Gdogw',
authDomain: 'vexillology-contests.firebaseapp.com',
projectId: 'vexillology-contests',
storageBucket: 'vexillology-contests.appspot.com',
messagingSenderId: '917790372061',
appId: '1:917790372061:web:27bdbeffebe44caf4d2b34',
measurementId: 'G-DD6MTL11SP',
};

const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);

export default analytics;
1 change: 1 addition & 0 deletions react-ui/src/common/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as DrawerStateContext } from './DrawerStateContext';
export { default as analytics } from './firebase';
export { default as useClientWidth } from './useClientWidth';
export { default as useSwrData } from './useSwrData';
17 changes: 17 additions & 0 deletions react-ui/src/components/Analytics.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { logEvent } from 'firebase/analytics';
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

import { analytics } from '../common';

const Analytics = () => {
const location = useLocation();

useEffect(() => {
logEvent(analytics, 'page_view', { page_path: location.pathname });
}, [location]);

return null;
};

export default Analytics;
1 change: 1 addition & 0 deletions react-ui/src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as Analytics } from './Analytics';
export { default as AppBarDivided } from './AppBarDivided';
export { default as AppBarIconButton } from './AppBarIconButton';
export { default as ArrowBackButton } from './ArrowBackButton';
Expand Down