Skip to content

Commit 8e2fc1f

Browse files
committed
Added click tracker
1 parent 30ce291 commit 8e2fc1f

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/analytics/analytics.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@ export const sendPageView = (url: string) => {
1212
} else {
1313
console.warn('gtag is not defined');
1414
}
15+
};
16+
17+
export const sendClickEvent = (category: string, label: string) => {
18+
if (typeof window.gtag === 'function') {
19+
window.gtag('event', 'click', {
20+
event_category: category,
21+
event_label: label,
22+
});
23+
}
1524
};

src/features/ConnectPage.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { motion as m } from 'framer-motion';
88
import useAnimationState from "../hooks/useAnimationState";
99
import CloseIcon from '@mui/icons-material/Close';
1010
import SendIcon from '@mui/icons-material/Send';
11+
import { sendClickEvent } from "../analytics/analytics";
1112

1213
type Message = {
1314
title: string;
@@ -52,6 +53,10 @@ function ContactsPage() {
5253
);
5354
};
5455

56+
const handleClick = (btnName: string) => {
57+
sendClickEvent('Connect', `Clicked ${btnName}`);
58+
}
59+
5560
return (
5661
<m.div
5762
initial={{ y: "100%" }}
@@ -83,6 +88,7 @@ function ContactsPage() {
8388
href="https://www.linkedin.com/in/karol-topchiev-787b85a8/"
8489
target="_blank"
8590
sx={{ color: '#6eccfa', '&: hover': { color: 'white' } }}
91+
onClick={() => handleClick('LinkedIn button')}
8692
>
8793
<FontAwesomeIcon
8894
icon={faLinkedin}
@@ -93,6 +99,7 @@ function ContactsPage() {
9399
href="https://github.com/ktopchiev"
94100
target="_blank"
95101
sx={{ color: 'darkgray', '&: hover': { color: 'white' } }}
102+
onClick={() => handleClick('GitHub button')}
96103
>
97104
<FontAwesomeIcon
98105
icon={faGithub}

src/features/projects/ProjectCard.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ import { Box, CardActionArea, Chip, Grid, IconButton, styled } from '@mui/materi
88
import Project from '../../models/project';
99
import { faGithub } from "@fortawesome/free-brands-svg-icons"
1010
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
11+
import { sendClickEvent } from '../../analytics/analytics';
1112

1213
interface Props {
1314
project: Project
1415
}
1516

1617
export default function ProjectCard({ project }: Props) {
1718

18-
const handleClick = (url: string) => {
19+
const handleClick = (url: string, btnName: string) => {
1920
window.open(url, 'blank')?.focus();
21+
sendClickEvent('Projects', `Clicked ${btnName}`);
2022
};
2123

2224
const styles = {
@@ -62,7 +64,7 @@ export default function ProjectCard({ project }: Props) {
6264
sx={styles.card}
6365
>
6466
<StyledCardActionArea
65-
onClick={() => handleClick(project.url)}
67+
onClick={() => handleClick(project.url, 'Card')}
6668
>
6769
<CardHeader
6870
title={project.title}
@@ -95,7 +97,7 @@ export default function ProjectCard({ project }: Props) {
9597
</StyledCardActionArea>
9698
<CardActions sx={{ display: 'flex', justifyContent: 'flex-end' }}>
9799
<IconButton
98-
onClick={() => handleClick(project.repoUrl)}
100+
onClick={() => handleClick(project.repoUrl, 'GitHub button')}
99101
sx={styles.button}
100102
>
101103
<FontAwesomeIcon

0 commit comments

Comments
 (0)