Skip to content

Commit 3b3b3d5

Browse files
committed
handle click events across cards, links, and filter
Signed-off-by: Sandeep Parikh <sandpari@qti.qualcomm.com>
1 parent 9e6cca0 commit 3b3b3d5

3 files changed

Lines changed: 49 additions & 8 deletions

File tree

src/components/ProjectCard.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Card from 'react-bootstrap/Card';
66
import Col from 'react-bootstrap/Col';
77
import Badge from 'react-bootstrap/Badge';
88

9+
import ReactGA from "react-ga4";
10+
911
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
1012
import { library } from '@fortawesome/fontawesome-svg-core'
1113
import { fas } from '@fortawesome/free-solid-svg-icons'
@@ -15,18 +17,26 @@ library.add(fas)
1517
const ProjectCard = ({ project }) => {
1618
const { name, author, stars, language, link, lastUpdated, platforms, categories, description } = project;
1719

20+
const handleCardClick = (label, type) => {
21+
ReactGA.event({
22+
category: 'Project',
23+
action: `Clicked ${type} Link`,
24+
label: label
25+
});
26+
};
27+
1828
return (
1929
<Col md={6} lg={4} className="mb-4">
2030
<Card className="h-100 shadow-sm">
2131
<Card.Header>
22-
<Card.Link href={link} target="_blank" rel="noopener noreferrer" className="fw-bold text-decoration-none">
32+
<Card.Link href={link} onClick={() => handleCardClick(name, "Project")} target="_blank" rel="noopener noreferrer" className="fw-bold text-decoration-none">
2333
{name}<FontAwesomeIcon icon="fa-solid fa-arrow-up-right-from-square" className="ms-2" />
2434
</Card.Link>
2535
</Card.Header>
2636
<Card.Body className="d-flex flex-column">
2737
<Card.Text>{description}</Card.Text>
2838
<Card.Subtitle className="mt-auto mb-2 text-muted small">
29-
By: <Card.Link href={`https://github.com/${author}`} target="_blank" rel="noopener noreferrer" className="text-decoration-none">{author}</Card.Link>
39+
By: <Card.Link href={`https://github.com/${author}`} onClick={() => handleCardClick(author, "Author")} target="_blank" rel="noopener noreferrer" className="text-decoration-none">{author}</Card.Link>
3040
</Card.Subtitle>
3141
<Card.Text className="text-muted small">
3242
<FontAwesomeIcon icon="fa-solid fa-code" /> {language}

src/components/ProjectCarousel.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@ import Col from 'react-bootstrap/Col';
77
import Carousel from 'react-bootstrap/Carousel';
88
import Card from 'react-bootstrap/Card';
99

10+
import ReactGA from "react-ga4";
11+
1012
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
1113
import { library } from '@fortawesome/fontawesome-svg-core'
1214
import { fas } from '@fortawesome/free-solid-svg-icons'
1315
import { fab } from '@fortawesome/free-brands-svg-icons'
1416

1517
library.add(fas, fab)
1618

17-
18-
1919
const ProjectCarousel = ({ projects }) => {
2020
const showcaseProjects = projects.filter(p => p.isShowcase);
2121

22+
const handleLinkClick = (category, label, type) => {
23+
ReactGA.event({
24+
category: category,
25+
action: `Clicked ${type} Link`,
26+
label: label
27+
});
28+
};
29+
2230
const quickLinks = [
2331
{ name: 'Qualcomm on GitHub', url: 'https://github.com/Qualcomm', icon: 'fa-brands fa-github' },
2432
{ name: 'Qualcomm Developers', url: 'https://www.qualcomm.com/developer', icon: 'fa-solid fa-laptop-code' },
@@ -41,19 +49,19 @@ const ProjectCarousel = ({ projects }) => {
4149
<Card className="shadow-sm pb-4">
4250
<Card.Body>
4351
<Card.Title className="mb-2">
44-
<Card.Link href={project.link} target="_blank" rel="noopener noreferrer" className="fw-bold text-decoration-none small">
52+
<Card.Link href={project.link} onClick={() => { handleLinkClick("Project", project.name, "Project"); }} target="_blank" rel="noopener noreferrer" className="fw-bold text-decoration-none small">
4553
{project.name}<FontAwesomeIcon icon="fa-solid fa-arrow-up-right-from-square" className="ms-2" />
4654
</Card.Link>
4755
</Card.Title>
4856
<Card.Subtitle className="mb-2 text-muted small">
4957
By:&nbsp;
50-
<Card.Link href={`https://github.com/${project.author}`} target="_blank" rel="noopener noreferrer" className="text-decoration-none">
58+
<Card.Link href={`https://github.com/${project.author}`} onClick={() => { handleLinkClick("Project", project.author, "Author"); }} target="_blank" rel="noopener noreferrer" className="text-decoration-none">
5159
{project.author}
5260
</Card.Link>
5361
</Card.Subtitle>
5462
<Card.Text className="small">{project.description}</Card.Text>
5563
<Card.Text>
56-
<a href={project.link} target="_blank" rel="noopener noreferrer" className="card-link">
64+
<a href={project.link} onClick={() => { handleLinkClick("Project", project.name, "Project"); }} target="_blank" rel="noopener noreferrer" className="card-link">
5765
View Project
5866
</a>
5967
</Card.Text>
@@ -68,7 +76,7 @@ const ProjectCarousel = ({ projects }) => {
6876
<ul className="list-unstyled">
6977
{quickLinks.map(link => (
7078
<li key={link.name}>
71-
<a href={link.url} target="_blank" rel="noopener noreferrer" className=" text-decoration-none">
79+
<a href={link.url} onClick={() => { handleLinkClick("Quick Link", link.name, "Quick"); }} target="_blank" rel="noopener noreferrer" className=" text-decoration-none">
7280
<FontAwesomeIcon icon={link.icon} className="ms-2" /> {link.name}
7381
</a>
7482
</li>

src/components/ProjectFilter.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Form from 'react-bootstrap/Form';
99
import InputGroup from 'react-bootstrap/InputGroup';
1010
import Button from 'react-bootstrap/Button';
1111

12+
import ReactGA from 'react-ga4'
13+
1214
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
1315
import { library } from '@fortawesome/fontawesome-svg-core'
1416
import { fas } from '@fortawesome/free-solid-svg-icons'
@@ -53,6 +55,13 @@ const ProjectFilter = ({ allProjects }) => {
5355
if (search) params.set('search', search);
5456
params.set('sort', sort);
5557
params.set('direction', direction);
58+
59+
ReactGA.event({
60+
category: "Filter",
61+
action: "Update Filter",
62+
label: `Platforms: ${platforms.join(', ')}, Categories: ${categories.join(', ')}, Search: ${search}, Sort: ${sort}, Direction: ${direction}`
63+
})
64+
5665
navigate(`/?${params.toString()}`);
5766
};
5867

@@ -64,6 +73,13 @@ const ProjectFilter = ({ allProjects }) => {
6473
} else {
6574
newPlatforms = [...currentPlatforms, platform];
6675
}
76+
77+
ReactGA.event({
78+
category: "Filter",
79+
action: "Select Platform",
80+
label: platform
81+
})
82+
6783
updateFilter(newPlatforms, currentCategories);
6884
};
6985

@@ -80,6 +96,13 @@ const ProjectFilter = ({ allProjects }) => {
8096
} else {
8197
newCategories = [...currentCategories, category];
8298
}
99+
100+
ReactGA.event({
101+
category: "Filter",
102+
action: "Select Category",
103+
label: category
104+
})
105+
83106
updateFilter(currentPlatforms, newCategories);
84107
};
85108

0 commit comments

Comments
 (0)