Skip to content

Commit

Permalink
feat(studies): SKFP-1389 add GA tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
GaelleA committed Dec 6, 2024
1 parent dc46951 commit 9f839c7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
35 changes: 26 additions & 9 deletions src/components/PublicLayout/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import KidsFirstIcon from 'components/Icons/KidsFirstIcon';
import LineStyleIcon from 'components/Icons/LineStyleIcon';
import GradientAccent from 'components/uiKit/GradientAccent';
import useQueryParams from 'hooks/useQueryParams';
import { trackVisitResources } from 'services/analytics';
import { trackPublicStudies, trackVisitResources } from 'services/analytics';
import { SUPPORT_EMAIL } from 'store/report/thunks';
import { STATIC_ROUTES } from 'utils/routes';

Expand All @@ -41,7 +41,8 @@ const Header = () => {
const [openLoginModal, setOpenLoginModal] = useState(false);
const closeLoginModal = () => setOpenLoginModal(false);

const handleSignin = async () => {
const handleSignin = async (btnName: string) => {
trackPublicStudies(btnName);
const url = keycloak.createLoginUrl({
redirectUri: `${window.location.origin}/${
query.get(REDIRECT_URI_KEY) || STATIC_ROUTES.DASHBOARD
Expand All @@ -61,7 +62,10 @@ const Header = () => {
<HeaderButton
key="dashboard"
icon={<HomeOutlined />}
onClick={() => setOpenLoginModal(true)}
onClick={() => {
trackPublicStudies('Dashboard');
setOpenLoginModal(true);
}}
title={intl.get('layout.main.menu.dashboard')}
/>
<HeaderButton
Expand All @@ -73,13 +77,19 @@ const Header = () => {
<HeaderButton
key="explore-data"
icon={<FileSearchOutlined />}
onClick={() => setOpenLoginModal(true)}
onClick={() => {
trackPublicStudies('Data Exploration');
setOpenLoginModal(true);
}}
title={intl.get('layout.main.menu.explore')}
/>
<HeaderButton
key="variant-data"
icon={<LineStyleIcon />}
onClick={() => setOpenLoginModal(true)}
onClick={() => {
trackPublicStudies('Variants');
setOpenLoginModal(true);
}}
title={intl.get('layout.main.menu.variants')}
/>
</nav>
Expand All @@ -88,7 +98,10 @@ const Header = () => {
<HeaderButton
key="community"
icon={<TeamOutlined />}
onClick={() => setOpenLoginModal(true)}
onClick={() => {
trackPublicStudies('Community');
setOpenLoginModal(true);
}}
title={intl.get('layout.main.menu.community')}
/>,
<Dropdown
Expand Down Expand Up @@ -165,12 +178,16 @@ const Header = () => {
<div className={style.connectionWrapper}>
<HeaderButton
className={style.loginBtn}
key="community"
key="login"
icon={<LoginOutlined />}
onClick={handleSignin}
onClick={() => handleSignin('Login')}
title={intl.get('screen.loginPage.login')}
/>
<Button className={style.signUpBtn} onClick={handleSignin} type="primary">
<Button
className={style.signUpBtn}
onClick={() => handleSignin('Sign Up')}
type="primary"
>
{intl.get('screen.loginPage.signup')}
</Button>
</div>,
Expand Down
8 changes: 5 additions & 3 deletions src/components/PublicLayout/LoginModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import useQueryParams from 'hooks/useQueryParams';
import { STATIC_ROUTES } from 'utils/routes';

import style from './index.module.css';
import { trackPublicStudies } from 'services/analytics';

const { Title, Paragraph } = Typography;

Expand All @@ -22,7 +23,8 @@ const LoginModal = ({ isOpen, onClose }: LoginModalProps) => {
const { keycloak } = useKeycloak();
const query = useQueryParams();

const handleSignin = async () => {
const handleSignin = async (btnName: string) => {
trackPublicStudies(btnName);
const url = keycloak.createLoginUrl({
redirectUri: `${window.location.origin}/${
query.get(REDIRECT_URI_KEY) || STATIC_ROUTES.DASHBOARD
Expand Down Expand Up @@ -61,10 +63,10 @@ const LoginModal = ({ isOpen, onClose }: LoginModalProps) => {
</Paragraph>
</div>
<Space size={24}>
<LandingPageButton alt onClick={handleSignin} size="large">
<LandingPageButton alt onClick={() => handleSignin('Modal Login')} size="large">
{intl.get('screen.publicStudies.loginModal.login')}
</LandingPageButton>
<LandingPageButton onClick={handleSignin} size="large">
<LandingPageButton onClick={() => handleSignin('Modal Sign up')} size="large">
{intl.get('screen.publicStudies.loginModal.signup')}
</LandingPageButton>
</Space>
Expand Down
18 changes: 18 additions & 0 deletions src/services/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,21 @@ export const trackKFConnection = (connected: boolean) => {
});
}
};

export const trackViewAllStudies = () => {
if (isGaActive) {
ReactGA.event({
category: 'Landing page',
action: 'Landing page - View all studies',
});
}
};

export const trackPublicStudies = (btnName: string) => {
if (isGaActive) {
ReactGA.event({
category: 'Public page',
action: `Public page - ${btnName}`,
});
}
};
8 changes: 7 additions & 1 deletion src/views/LandingPage/StudiesSection/Studies/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import LandingPageButton from 'views/LandingPage/Components/LandingPageButton';
import LandingPageTitle from 'views/LandingPage/Components/LandingPageTitle';

import studiesSvg from 'components/assets/kf-portal-icons_studies_2.svg';
import { trackViewAllStudies } from 'services/analytics';
import { useGlobals } from 'store/global';
import { STATIC_ROUTES } from 'utils/routes';

Expand All @@ -18,7 +19,12 @@ const StudiesSection = () => {
const navigate = useNavigate();
const publicStudiesBtn = getFTEnvVarByKey('PUBLIC_STUDIES');
const studiesBtnOnClick =
publicStudiesBtn === 'true' ? () => navigate(STATIC_ROUTES.PUBLIC_STUDIES) : undefined;
publicStudiesBtn === 'true'
? () => {
trackViewAllStudies();
navigate(STATIC_ROUTES.PUBLIC_STUDIES);
}
: undefined;

return (
<div className={styles.studiesContainer}>
Expand Down

0 comments on commit 9f839c7

Please sign in to comment.