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

feat: Added analytics logging on non-admin pages access #229

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
2 changes: 2 additions & 0 deletions pages/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import AnnouncementCard from '../../components/dashboardComponents/AnnouncementC
import Sidebar from '../../components/dashboardComponents/Sidebar';
import firebase from 'firebase';
import 'firebase/messaging';
import 'firebase/analytics';
import { GetServerSideProps } from 'next';
import { RequestHelper } from '../../lib/request-helper';
import { useFCMContext } from '../../lib/service-worker/FCMContext';
Expand Down Expand Up @@ -42,6 +43,7 @@ export default function Dashboard(props: {
const [challenges, setChallenges] = useState<Challenge[]>([]);

useEffect(() => {
firebase.analytics().logEvent('access_dashboard');
DedsecKnight marked this conversation as resolved.
Show resolved Hide resolved
setAnnouncements(props.announcements);
// ordering challenges as speficied in firebase
setChallenges(props.challenges.sort((a, b) => (a.rank > b.rank ? 1 : -1)));
Expand Down
6 changes: 6 additions & 0 deletions pages/dashboard/questions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { RequestHelper } from '../../lib/request-helper';
import { useAuthContext } from '../../lib/user/AuthContext';
import { QAReqBody } from '../api/questions';
import DashboardHeader from '../../components/dashboardComponents/DashboardHeader';
import firebase from 'firebase/app';
import 'firebase/analytics';
/**
* The Question and Answers page.
*
Expand All @@ -23,6 +25,10 @@ export default function QuestionsPage() {
const [answeredQuestionDisclosureStatus, setAnsweredDisclosureStatus] = useState<boolean[]>([]);
const { user, isSignedIn, hasProfile } = useAuthContext();

useEffect(() => {
firebase.analytics().logEvent('access_ask_question_page');
}, []);

/**
*
* Fetch all answered questions that are asked by current user
Expand Down
7 changes: 6 additions & 1 deletion pages/hackerpacks/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import React, { useEffect } from 'react';
DedsecKnight marked this conversation as resolved.
Show resolved Hide resolved
import { GetStaticProps } from 'next';
import { NotionAPI } from 'notion-client';
import hackerpackSettings from '../../components/hackerpackComponents/hackerpack-settings.json';
import HackerpackDisplay from '../../components/hackerpackComponents/HackerpackDisplay';
import firebase from 'firebase/app';
import 'firebase/analytics';

/**
* The hackerpack page.
Expand All @@ -11,6 +13,9 @@ import HackerpackDisplay from '../../components/hackerpackComponents/HackerpackD
*/
export default function HackerPack(props: { content: any }) {
// Find the root block because Notion IDs have hyphens
useEffect(() => {
firebase.analytics().logEvent('access_hackerpack');
}, []);
const rootId =
hackerpackSettings.mainContent === 'notion'
? Object.keys(props.content.block).find(
Expand Down
5 changes: 5 additions & 0 deletions pages/index.tsx
DedsecKnight marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Head from 'next/head';
import firebase from 'firebase/app';
import 'firebase/analytics';
import { GetServerSideProps } from 'next';
import { useEffect, useState } from 'react';
import { RequestHelper } from '../lib/request-helper';
Expand All @@ -11,6 +13,7 @@ import HomeChallenges from '../components/homeComponents/HomeChallenges';
import HomeTeam from '../components/homeComponents/HomeTeam';
import HomeSponsors from '../components/homeComponents/HomeSponsors';
import HomeFooter from '../components/homeComponents/HomeFooter';
import { useAuthContext } from '../lib/user/AuthContext';

/**
* The home page.
Expand All @@ -26,8 +29,10 @@ export default function Home(props: {
sponsorCard: Sponsor[];
}) {
const [loading, setLoading] = useState(true);
const { user } = useAuthContext();

useEffect(() => {
firebase.analytics().logEvent('access_home_page');
// Wait for all components to render before showing page
setLoading(false);
}, []);
Expand Down
7 changes: 6 additions & 1 deletion pages/profile.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useRouter } from 'next/router';
import Image from 'next/image';
import React, { useRef, useState } from 'react';
import firebase from 'firebase/app';
import 'firebase/analytics';
import React, { useEffect, useRef, useState } from 'react';
DedsecKnight marked this conversation as resolved.
Show resolved Hide resolved
import { useAuthContext } from '../lib/user/AuthContext';
import LoadIcon from '../components/LoadIcon';
import { getFileExtension } from '../lib/util';
Expand Down Expand Up @@ -57,6 +59,9 @@ export default function ProfilePage() {
}
});
};
useEffect(() => {
firebase.analytics().logEvent('access_profile_page');
}, []);
DedsecKnight marked this conversation as resolved.
Show resolved Hide resolved

if (!isSignedIn) {
return <div className="p-4 flex-grow text-center">Sign in to see your profile!</div>;
Expand Down
2 changes: 2 additions & 0 deletions pages/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useUser } from '../lib/profile/user-data';
import { RequestHelper } from '../lib/request-helper';
import { useAuthContext } from '../lib/user/AuthContext';
import firebase from 'firebase/app';
import 'firebase/analytics';
import { Formik, Form, Field, ErrorMessage } from 'formik';
import schools from '../public/schools.json';
import majors from '../public/majors.json';
Expand Down Expand Up @@ -43,6 +44,7 @@ export default function Register() {

useEffect(() => {
//setting user specific initial values
firebase.analytics().logEvent('access_register_page');
DedsecKnight marked this conversation as resolved.
Show resolved Hide resolved
formInitialValues['id'] = user?.id || '';
formInitialValues['preferredEmail'] = user?.preferredEmail || '';
formInitialValues['firstName'] = user?.firstName || '';
Expand Down
4 changes: 4 additions & 0 deletions pages/schedule/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import ClockIcon from '@material-ui/icons/AccessTime';
import Backpack from '@material-ui/icons/LocalMall';
import Description from '@material-ui/icons/BorderColor';
import firebase from 'firebase';
import 'firebase/analytics';

const styles = ({ palette }: Theme) =>
createStyles({
Expand Down Expand Up @@ -127,6 +128,9 @@ const AppointmentContent = withStyles(styles, { name: 'AppointmentContent' })(
);

export default function Calendar(props: { scheduleCard: ScheduleEvent[] }) {
useEffect(() => {
firebase.analytics().logEvent('access_schedule_page');
}, []);
// Hooks
const [eventData, setEventData] = useState({
title: '',
Expand Down