Skip to content

Commit

Permalink
Merge pull request #279 from Rushikesh-Sonawane99/shiksha-2.0
Browse files Browse the repository at this point in the history
PS-Issue #PS-906 feat: Added user events to track in google Analytics
  • Loading branch information
itsvick authored Jun 13, 2024
2 parents 9a9250b + 6e8cc88 commit 76d76fa
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 14 deletions.
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
NEXT_PUBLIC_BASE_URL=https://qa.prathamteacherapp.tekdinext.com/user/v1
NEXT_PUBLIC_ANALYTICS_ID=abcdefghijk
NEXT_PUBLIC_MEASUREMENT_ID= G-GNMQZ8Z65Z
19 changes: 15 additions & 4 deletions src/components/DateRangePopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useStepContext,
} from '@mui/material';
import React, { useState } from 'react';
import ReactGA from 'react-ga4';
import { getDayAndMonthName, getTodayDate } from '@/utils/Helper';

import checkMark from '../assets/images/checkMark.svg';
Expand Down Expand Up @@ -86,8 +87,15 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({
getDayAndMonthName(getTodayDate())
);
const [cancelClicked, setCancelClicked] = React.useState(false);
const [appliedOption, setAppliedOption] = React.useState<string>('');
const [appliedIndex, setAppliedIndex] = React.useState<number | null>(0);

const toggleModal = () => setIsModalOpen(!isModalOpen);
const handleModalClose = () =>{
setIsModalOpen(false)
setSelectedValue(appliedOption)
setSelectedIndex(appliedIndex)
}
const toggleCalendarModal = () =>
setIsCalenderModalOpen(!isCalendarModalOpen);
const { t } = useTranslation();
Expand All @@ -113,10 +121,13 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({
setSelectedValue('');
setCancelClicked(false);
} else {
console.log('applied', selectedIndex, selectedValue);
// console.log('applied', selectedIndex, selectedValue);
setAppliedOption(selectedValue)
setAppliedIndex(selectedIndex)
ReactGA.event("date-range-pop-up-clicked", { dateRangeType: selectedValue});
const values = getDateRange(selectedIndex);
const { toDate, fromDate } = values;
console.log(toDate, fromDate);
// console.log(toDate, fromDate);
onDateRangeSelected({ fromDate, toDate });
toggleModal();
}
Expand Down Expand Up @@ -225,7 +236,7 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({

<Modal
open={isModalOpen}
onClose={toggleModal}
onClose={handleModalClose}
aria-labelledby="edit-profile-modal"
aria-describedby="edit-profile-description"
>
Expand All @@ -244,7 +255,7 @@ const DateRangePopup: React.FC<CustomSelectModalProps> = ({
</Typography>
</Grid>
<Grid item xs={6} textAlign={'right'}>
<CloseIcon className="text4D" onClick={toggleModal} />
<CloseIcon className="text4D" onClick={handleModalClose} />
</Grid>
</Grid>
</Box>
Expand Down
11 changes: 11 additions & 0 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Image from 'next/image';
import logoLight from '../../public/images/logo-light.png';
import menuIcon from '../assets/images/menuIcon.svg';
import accountIcon from './../assets/images/account.svg';
import { logEvent } from '@/utils/googleAnalytics';

const Header: React.FC = () => {
const router = useRouter();
Expand Down Expand Up @@ -69,10 +70,20 @@ const Header: React.FC = () => {
const handleProfileClick = () => {
if (pathname !== '/profile') {
router.push('/profile');
logEvent({
action: 'my-profile-clicked-header',
category: 'Dashboard',
label: 'Profile Clicked',
});
}
};
const handleLogoutClick = () => {
router.replace('/logout');
logEvent({
action: 'logout-clicked-header',
category: 'Dashboard',
label: 'Logout Clicked',
});
};
const [openDrawer, setOpenDrawer] = useState<boolean>(false);

Expand Down
5 changes: 4 additions & 1 deletion src/components/LearnerAttendanceStatsListView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box, Grid, Stack, Typography, useMediaQuery } from '@mui/material';
import React, { useState } from 'react';
import ReactGA from 'react-ga4';
import { UserData, updateCustomField } from '@/utils/Interfaces';

import LearnerModal from './LearnerModal';
Expand Down Expand Up @@ -130,7 +131,9 @@ const StudentsStatsList: React.FC<StudentsStatsListProps> = ({
<Grid item xs={6} textAlign={'left'}>
<Link className="word-break" href={''}>
<Typography
onClick={() => handleOpenModalLearner(userId!)}
onClick={() => {handleOpenModalLearner(userId!)
ReactGA.event("learner-details-link-clicked", { userId: userId});
}}
sx={{
textAlign: 'left',
fontSize: '14px',
Expand Down
9 changes: 9 additions & 0 deletions src/components/SortingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import ReactGA from 'react-ga4';

import {
FormControl,
Expand Down Expand Up @@ -88,6 +89,14 @@ const SortingModal: React.FC<sortCardProps> = ({
sortByClassesMissed,
sortByAttendanceNumber
);
ReactGA.event('sort-by-applied', {
sortingBasis: [
sortByName,
sortByAttendance,
sortByClassesMissed,
sortByAttendanceNumber,
],
});
handleCloseModal();
};

Expand Down
19 changes: 19 additions & 0 deletions src/components/UpDownButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
import { Box } from '@mui/material';
import { usePathname } from 'next/navigation';
import { useTranslation } from 'next-i18next';
import { logEvent } from '@/utils/googleAnalytics';

const UpDownButton = () => {
const [isVisible, setIsVisible] = useState(false);
Expand Down Expand Up @@ -49,6 +50,22 @@ const UpDownButton = () => {
}
}, [pathname]);

const handleBackToTopButtonClicked = () =>{
logEvent({
action: 'back-to-top-button-clicked',
category: 'Attendance Overview/ History Page',
label: 'Back To Top Clicked',
});
}

const handleLearnerButtonClicked = () =>{
logEvent({
action: 'learners-button-clicked',
category: 'Attendance Overview/ History Page',
label: 'Learners Button Clicked',
});
}

return (
<div>
{isVisible && (
Expand All @@ -61,6 +78,7 @@ const UpDownButton = () => {
<Box
sx={{ height: '88px', width: '64px' }}
className="flex-column-center"
onClick={handleBackToTopButtonClicked}
>
<ArrowUpwardIcon />
<span className="w-78"> {t('DASHBOARD.BACK_TO_TOP')}</span>
Expand All @@ -69,6 +87,7 @@ const UpDownButton = () => {
<Box
sx={{ height: '80px', width: '64px' }}
className="flex-column-center"
onClick={handleLearnerButtonClicked}
>
{t('COMMON.LEARNERS')}
<ArrowDownwardIcon />
Expand Down
11 changes: 10 additions & 1 deletion src/pages/attendance-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Typography,
} from '@mui/material';
import React, { useEffect, useRef, useState } from 'react';
import ReactGA from 'react-ga4';
import {
debounce,
getTodayDate,
Expand Down Expand Up @@ -49,6 +50,7 @@ import { useRouter } from 'next/router';
import { useTheme } from '@mui/material/styles';
import { useTranslation } from 'next-i18next';
import ToastMessage from '@/components/ToastMessage';
import { logEvent } from '@/utils/googleAnalytics';

interface user {
userId: string;
Expand Down Expand Up @@ -404,6 +406,7 @@ const UserAttendanceHistory = () => {

const handleCohortSelection = (event: SelectChangeEvent) => {
setClassId(event.target.value as string);
ReactGA.event("cohort-selection-attendance-history-page", { selectedCohortID: event.target.value });
setHandleSaveHasRun(!handleSaveHasRun);

// ---------- set cohortId and stateName-----------
Expand Down Expand Up @@ -440,6 +443,7 @@ const UserAttendanceHistory = () => {
// handle search student data
const handleSearch = (event: React.ChangeEvent<HTMLInputElement>) => {
setSearchWord(event.target.value);
ReactGA.event("search-by-keyword-attendance-history-age", { keyword: event.target.value});
if (event.target.value.length >= 3) {
debouncedSearch(event.target.value);
} else {
Expand Down Expand Up @@ -570,7 +574,12 @@ const UserAttendanceHistory = () => {
width={'100%'}
paddingTop={'10px'}
>
<Box onClick={() => window.history.back()}>
<Box onClick={() => {window.history.back()
logEvent({
action: 'back-button-clicked-attendance-history-page',
category: 'Attendance History Page',
label: 'Back Button Clicked',
});}}>
<Box>
<KeyboardBackspaceOutlinedIcon
cursor={'pointer'}
Expand Down
9 changes: 9 additions & 0 deletions src/pages/attendance-overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Typography,
} from '@mui/material';
import React, { useEffect, useRef, useState } from 'react';
import ReactGA from 'react-ga4';
import {
classesMissedAttendancePercentList,
getAllCenterAttendance,
Expand Down Expand Up @@ -50,6 +51,7 @@ import { usePathname } from 'next/navigation';
import { useRouter } from 'next/router';
import { useTheme } from '@mui/material/styles';
import { useTranslation } from 'next-i18next';
import { logEvent } from '@/utils/googleAnalytics';

interface AttendanceOverviewProps {
// buttonText: string;
Expand Down Expand Up @@ -454,6 +456,7 @@ const AttendanceOverview: React.FC<AttendanceOverviewProps> = () => {

const handleCohortSelection = (event: SelectChangeEvent) => {
setClassId(event.target.value as string);
ReactGA.event("cohort-selection-attendance-overview-page", { selectedCohortID: event.target.value });

// ---------- set cohortId and stateName-----------
const cohort_id = event.target.value;
Expand Down Expand Up @@ -491,6 +494,7 @@ const AttendanceOverview: React.FC<AttendanceOverviewProps> = () => {
setSearchWord(event.target.value);
if (event.target.value.length >= 1) {
debouncedSearch(event.target.value);
ReactGA.event("search-by-keyword-attendance-overview-page", { keyword: event.target.value});
} else {
setDisplayStudentList(learnerData);
}
Expand Down Expand Up @@ -585,6 +589,11 @@ const AttendanceOverview: React.FC<AttendanceOverviewProps> = () => {
};
const handleBackEvent = () => {
window.history.back();
logEvent({
action: 'back-button-clicked-attendance-overview',
category: 'Attendance Overview Page',
label: 'Back Button Clicked',
});
};
const truncate = (str: string, length: number) => {
if (str.length <= length) return str;
Expand Down
20 changes: 19 additions & 1 deletion src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '@mui/material';
import { CircularProgressbar, buildStyles } from 'react-circular-progressbar';
import React, { useEffect, useState } from 'react';
import ReactGA from 'react-ga4';
// import Snackbar, { SnackbarOrigin } from '@mui/material/Snackbar';
import {
classesMissedAttendancePercentList,
Expand Down Expand Up @@ -56,6 +57,7 @@ import useDeterminePathColor from '../hooks/useDeterminePathColor';
import { useRouter } from 'next/navigation';
import { useTheme } from '@mui/material/styles';
import { useTranslation } from 'next-i18next';
import { logEvent } from '@/utils/googleAnalytics';

// interface State extends SnackbarOrigin {
// openModal: boolean;
Expand Down Expand Up @@ -398,10 +400,16 @@ const Dashboard: React.FC<DashboardProps> = () => {
setShowDetails(true);
};

const handleModalToggle = () => setOpen(!open);
const handleModalToggle = () => {setOpen(!open)
logEvent({
action: 'mark/modify-attendance-button-clicked-dashboard',
category: 'Dashboard Page',
label: 'Mark/ Modify Attendance',
})};

const handleCohortSelection = (event: SelectChangeEvent) => {
setClassId(event.target.value as string);
ReactGA.event("cohort-selection-dashboard", { selectedCohortID: event.target.value });
localStorage.setItem('classId', event.target.value);
setHandleSaveHasRun(!handleSaveHasRun);
};
Expand Down Expand Up @@ -470,6 +478,7 @@ const Dashboard: React.FC<DashboardProps> = () => {
const viewAttendanceHistory = () => {
if (classId !== 'all') {
router.push('/attendance-history');
ReactGA.event("month-name-clicked", { selectedCohortID: classId });
}
};

Expand Down Expand Up @@ -502,6 +511,14 @@ const Dashboard: React.FC<DashboardProps> = () => {
return str.slice(0, length) + '...';
};

const handleMoreDetailsClicked = () => {
logEvent({
action: 'more-details-button-clicked',
category: 'Dashboard Page',
label: 'More Details Link Clicked',
});
};

return (
<>
{!isAuthenticated && (
Expand Down Expand Up @@ -834,6 +851,7 @@ const Dashboard: React.FC<DashboardProps> = () => {
color: theme.palette.secondary.main,
fontWeight: '500',
}}
onClick={handleMoreDetailsClicked}
>
{t('DASHBOARD.MORE_DETAILS')}
<ArrowForwardSharpIcon sx={{ height: '18px' }} />
Expand Down
11 changes: 11 additions & 0 deletions src/pages/learner-attendance-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useTheme } from '@mui/material/styles';
import { useTranslation } from 'next-i18next';
import { useRouter } from 'next/router';
import ToastMessage from '@/components/ToastMessage';
import { logEvent } from '@/utils/googleAnalytics';

type LearnerAttendanceData = {
[date: string]: {
Expand Down Expand Up @@ -69,6 +70,11 @@ const LearnerAttendanceHistory = () => {

const handleOpen = () => {
setOpen(true);
logEvent({
action: 'individual-learner-attendance-modal-open',
category: 'Learner Attendance History Page',
label: 'Mark Individual Learner Modal Open',
});
};

const handleModalOpen = () => {
Expand All @@ -77,6 +83,11 @@ const LearnerAttendanceHistory = () => {

const handleModalClose = () => {
setOpen(false);
logEvent({
action: 'individual-learner-attendance-modal-close',
category: 'Learner Attendance History Page',
label: 'Mark Individual Learner Modal Close',
});
};

useEffect(() => {
Expand Down
Loading

0 comments on commit 76d76fa

Please sign in to comment.