|
1 | 1 | import declareGlobal from "../libs/declare"; |
| 2 | +import { trackFeaturedSnapClicked } from "../store/utils/featuredTracker"; |
2 | 3 |
|
3 | 4 | type PackageData = { |
4 | 5 | apps: Array<string>; |
@@ -31,21 +32,26 @@ async function buildCards(category: string): Promise<void> { |
31 | 32 | ); |
32 | 33 |
|
33 | 34 | featuredSnapCards.forEach((featuredSnapCard, index) => { |
34 | | - buildCard(featuredSnapCard, localData[index]); |
| 35 | + buildCard(featuredSnapCard, localData[index], category, index); |
35 | 36 | }); |
36 | 37 | } else { |
37 | 38 | const response = await fetch(`/store/featured-snaps/${category}`); |
38 | 39 | const data: Array<PackageData> = await response.json(); |
39 | 40 |
|
40 | 41 | featuredSnapCards.forEach((featuredSnapCard, index) => { |
41 | | - buildCard(featuredSnapCard, data[index]); |
| 42 | + buildCard(featuredSnapCard, data[index], category, index); |
42 | 43 | }); |
43 | 44 |
|
44 | 45 | window.sessionStorage.setItem(category, JSON.stringify(data)); |
45 | 46 | } |
46 | 47 | } |
47 | 48 |
|
48 | | -function buildCard(featuredSnapCard: Element, data: PackageData) { |
| 49 | +function buildCard( |
| 50 | + featuredSnapCard: Element, |
| 51 | + data: PackageData, |
| 52 | + category: string, |
| 53 | + index: number, |
| 54 | +) { |
49 | 55 | const placeholder = featuredSnapCard.querySelector( |
50 | 56 | "[data-js='featured-snap-card-placeholder']", |
51 | 57 | ) as HTMLElement; |
@@ -117,6 +123,16 @@ function buildCard(featuredSnapCard: Element, data: PackageData) { |
117 | 123 | } |
118 | 124 |
|
119 | 125 | content.appendChild(clone); |
| 126 | + |
| 127 | + content.addEventListener("click", () => { |
| 128 | + if (category === "featured") { |
| 129 | + trackFeaturedSnapClicked( |
| 130 | + data.package_name, |
| 131 | + index + 1, |
| 132 | + "home", |
| 133 | + ); |
| 134 | + } |
| 135 | + }); |
120 | 136 | } |
121 | 137 |
|
122 | 138 | placeholder.classList.add("u-hide"); |
|
0 commit comments