Skip to content

Commit 92467e2

Browse files
authored
chore(telemetry): measure homepage link clicks (#11978)
- Featured articles - Latest news - Recent contributions
1 parent 85b9436 commit 92467e2

File tree

4 files changed

+54
-13
lines changed

4 files changed

+54
-13
lines changed

client/src/homepage/featured-articles/index.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import useSWR from "swr";
2+
23
import { DEV_MODE } from "../../env";
34
import { HydrationData } from "../../../../libs/types/hydration";
5+
import { HOMEPAGE, HOMEPAGE_ITEMS } from "../../telemetry/constants";
46

57
import "./index.scss";
68

@@ -27,16 +29,25 @@ export default function FeaturedArticles(props: HydrationData<any>) {
2729
<div className="featured-articles">
2830
<h2>Featured articles</h2>
2931
<div className="tile-container">
30-
{hyData.featuredArticles.map((article) => {
32+
{hyData.featuredArticles.map((article, index) => {
3133
return (
3234
<div className="article-tile" key={article.mdn_url}>
3335
{article.tag && (
34-
<a href={article.tag.uri} className="tile-tag">
36+
<a
37+
href={article.tag.uri}
38+
className="tile-tag"
39+
data-glean={`${HOMEPAGE}: ${HOMEPAGE_ITEMS.ARTICLE_TAG} ${index + 1}`}
40+
>
3541
{article.tag.title}
3642
</a>
3743
)}
3844
<h3 className="tile-title">
39-
<a href={article.mdn_url}>{article.title}</a>
45+
<a
46+
href={article.mdn_url}
47+
data-glean={`${HOMEPAGE}: ${HOMEPAGE_ITEMS.ARTICLE} ${index + 1}`}
48+
>
49+
{article.title}
50+
</a>
4051
</h3>
4152
<p>{article.summary}</p>
4253
</div>

client/src/homepage/latest-news/index.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import dayjs from "dayjs";
22
import relativeTime from "dayjs/plugin/relativeTime";
33
import useSWR from "swr";
4+
45
import { DEV_MODE } from "../../env";
56
import { HydrationData } from "../../../../libs/types/hydration";
67
import { NewsItem } from "../../../../libs/types/document";
8+
import { HOMEPAGE, HOMEPAGE_ITEMS } from "../../telemetry/constants";
79

810
import "./index.scss";
911

@@ -35,13 +37,15 @@ export function LatestNews(props: HydrationData<any>) {
3537
return null;
3638
}
3739

38-
function NewsItemTitle({ newsItem }: { newsItem: NewsItem }) {
40+
function NewsItemTitle({ newsItem, ...attributes }: { newsItem: NewsItem }) {
3941
const ageInDays = dayjs().diff(newsItem.published_at, "day");
4042
const isNew = ageInDays < 7;
4143

4244
return (
4345
<>
44-
<a href={newsItem.url}>{newsItem.title}</a>
46+
<a href={newsItem.url} {...attributes}>
47+
{newsItem.title}
48+
</a>
4549
{isNew && (
4650
<>
4751
{" "}
@@ -52,11 +56,11 @@ export function LatestNews(props: HydrationData<any>) {
5256
);
5357
}
5458

55-
function NewsItemSource({ newsItem }: { newsItem: NewsItem }) {
59+
function NewsItemSource({ newsItem, ...attributes }: { newsItem: NewsItem }) {
5660
const { source } = newsItem;
5761

5862
return (
59-
<a className="news-source" href={source.url}>
63+
<a className="news-source" href={source.url} {...attributes}>
6064
{source.name}
6165
</a>
6266
);
@@ -72,14 +76,20 @@ export function LatestNews(props: HydrationData<any>) {
7276
<section className="latest-news">
7377
<h2>Latest news</h2>
7478
<ul className="news-list">
75-
{newsItems.map((newsItem) => (
79+
{newsItems.map((newsItem, index) => (
7680
<li className="news-item" key={newsItem.url}>
7781
<p className="news-title">
7882
<span>
79-
<NewsItemTitle newsItem={newsItem} />
83+
<NewsItemTitle
84+
newsItem={newsItem}
85+
data-glean={`${HOMEPAGE}: ${HOMEPAGE_ITEMS.NEWS} ${index + 1}`}
86+
/>
8087
</span>
8188
<span>
82-
<NewsItemSource newsItem={newsItem} />
89+
<NewsItemSource
90+
newsItem={newsItem}
91+
data-glean={`${HOMEPAGE}: ${HOMEPAGE_ITEMS.NEWS_SOURCE} ${index + 1}`}
92+
/>
8393
</span>
8494
</p>
8595
<span className="news-date" suppressHydrationWarning>

client/src/homepage/recent-contributions/index.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import dayjs from "dayjs";
22
import relativeTime from "dayjs/plugin/relativeTime";
33
import useSWR from "swr";
4+
45
import { DEV_MODE } from "../../env";
56
import { HydrationData } from "../../../../libs/types/hydration";
7+
import { HOMEPAGE, HOMEPAGE_ITEMS } from "../../telemetry/constants";
68

79
import "./index.scss";
810

@@ -33,12 +35,21 @@ function RecentContributions(props: HydrationData<any>) {
3335
<h2>Recent contributions</h2>
3436
<ul className="contribution-list">
3537
{hyData.recentContributions.items.map(
36-
({ number, url, title, updated_at, repo }) => (
38+
({ number, url, title, updated_at, repo }, index) => (
3739
<li className="request-item" key={number}>
3840
<p className="request-title">
39-
<a href={url}>{title}</a>
41+
<a
42+
href={url}
43+
data-glean={`${HOMEPAGE}: ${HOMEPAGE_ITEMS.CONTRIBUTION} ${index + 1}`}
44+
>
45+
{title}
46+
</a>
4047
<span>
41-
<a className="request-repo" href={repo.url}>
48+
<a
49+
className="request-repo"
50+
href={repo.url}
51+
data-glean={`${HOMEPAGE}: ${HOMEPAGE_ITEMS.CONTRIBUTION_REPO} ${index + 1}`}
52+
>
4253
{repo.name}
4354
</a>
4455
</span>

client/src/telemetry/constants.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,12 @@ export const LANGUAGE_REMEMBER = "language_remember";
8686
export const THEME_SWITCHER = "theme_switcher";
8787
export const SURVEY = "survey";
8888
export const HOMEPAGE_HERO = "homepage_hero";
89+
export const HOMEPAGE = "homepage";
90+
export const HOMEPAGE_ITEMS = Object.freeze({
91+
ARTICLE: "article",
92+
ARTICLE_TAG: "article_tag",
93+
NEWS: "news",
94+
NEWS_SOURCE: "news_source",
95+
CONTRIBUTION: "contribution",
96+
CONTRIBUTION_REPO: "contribution_repo",
97+
});

0 commit comments

Comments
 (0)