Skip to content

Commit 97056ff

Browse files
committed
feat: Enhance analytics tracking for user interactions with style filters and favorites
1 parent a13cbc5 commit 97056ff

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [2025.10.23] - 2025-10-23 08:33:51 UTC
11+
12+
13+
### Added
14+
- **Enhanced Analytics Tracking**: Added comprehensive tracking for user interactions including favorite toggles (add/remove with item names) and style filter selections (individual styles, select all, clear all) to better understand user preferences and behavior patterns
15+
1016
## [2025.10.23] - 2025-10-23 07:41:28 UTC
1117

1218

web/src/components/filters/StyleFilter.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import clsx from 'clsx';
3+
import { trackStyleSelection } from '../../services/analytics';
34

45
interface StyleFilterProps {
56
selectedStyles: ('regular' | 'filled' | 'light' | 'flat' | 'color')[];
@@ -31,20 +32,33 @@ export default function StyleFilter({
3132
className,
3233
}: StyleFilterProps) {
3334
const handleStyleToggle = (style: 'regular' | 'filled' | 'light' | 'flat' | 'color') => {
35+
let newStyles: ('regular' | 'filled' | 'light' | 'flat' | 'color')[];
36+
3437
if (selectedStyles.includes(style)) {
3538
// Remove the style
36-
onStylesChange(selectedStyles.filter(s => s !== style));
39+
newStyles = selectedStyles.filter(s => s !== style);
3740
} else {
3841
// Add the style
39-
onStylesChange([...selectedStyles, style]);
42+
newStyles = [...selectedStyles, style];
4043
}
44+
45+
// Track the style selection change
46+
trackStyleSelection(newStyles, availableStyles.length);
47+
48+
onStylesChange(newStyles);
4149
};
4250

4351
const handleSelectAll = () => {
52+
// Track selecting all styles
53+
trackStyleSelection(availableStyles, availableStyles.length);
54+
4455
onStylesChange(availableStyles);
4556
};
4657

4758
const handleClearAll = () => {
59+
// Track clearing all styles
60+
trackStyleSelection([], availableStyles.length);
61+
4862
onStylesChange([]);
4963
};
5064

web/src/components/icons/FavoriteButton.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { Icon, Emoji } from '../../types';
33
import { useFavorites } from '../../hooks/useFavorites';
44
import { StarIcon, StarIconFilled } from './MinimalIcons';
5+
import { trackFavoriteToggle } from '../../services/analytics';
56

67
interface FavoriteButtonProps {
78
item: Icon | Emoji;
@@ -18,6 +19,12 @@ const FavoriteButton: React.FC<FavoriteButtonProps> = ({ item, itemType, classNa
1819
e.preventDefault();
1920
e.stopPropagation();
2021

22+
const action = isItemFavorite ? 'remove' : 'add';
23+
const itemName = item.name || item.id;
24+
25+
// Track the favorite toggle event
26+
trackFavoriteToggle(itemType, itemName, action);
27+
2128
toggleFavorite(item, itemType);
2229
};
2330

web/src/components/layout/Sidebar.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { ChevronRightIcon, StarIconFilled } from '../icons/MinimalIcons';
33
import { useFavorites } from '../../hooks/useFavorites';
44
import { useAnalytics } from '../../hooks/useAnalytics';
5+
import { trackFilter } from '../../services/analytics';
56
import clsx from 'clsx';
67

78
interface Category {
@@ -94,6 +95,9 @@ export default function Sidebar({
9495
{/* Favorites */}
9596
<button
9697
onClick={() => {
98+
// Track favorites filter toggle
99+
trackFilter('favorites', showFavoritesOnly ? 'off' : 'on');
100+
97101
onToggleFavorites();
98102
// Clear category selection when favorites is toggled on
99103
if (!showFavoritesOnly && selectedCategory !== null) {

web/src/services/analytics.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,39 @@ export const trackExternalLink = (url: string, linkText: string): void => {
197197
export const trackError = (errorType: string, errorMessage: string): void => {
198198
trackEvent('error', 'application', `${errorType}: ${errorMessage}`);
199199
};
200+
201+
/**
202+
* Track favorite toggle events
203+
*/
204+
export const trackFavoriteToggle = (
205+
itemType: 'icon' | 'emoji',
206+
itemName: string,
207+
action: 'add' | 'remove'
208+
): void => {
209+
trackEvent(`favorite_${action}`, itemType, itemName);
210+
};
211+
212+
/**
213+
* Track style selection changes
214+
*/
215+
export const trackStyleSelection = (
216+
selectedStyles: string[],
217+
totalAvailableStyles: number
218+
): void => {
219+
const selectedCount = selectedStyles.length;
220+
const stylesList = selectedStyles.sort().join(', ') || 'none';
221+
222+
trackEvent('style_filter', 'filter', stylesList, selectedCount);
223+
224+
// Track specific analytics about style selection behavior
225+
if (selectedCount === 0) {
226+
trackEvent('style_filter_cleared', 'filter', 'all_styles_deselected');
227+
} else if (selectedCount === totalAvailableStyles) {
228+
trackEvent('style_filter_all', 'filter', 'all_styles_selected');
229+
} else {
230+
// Track individual popular styles
231+
selectedStyles.forEach(style => {
232+
trackEvent('style_selected', 'filter', style);
233+
});
234+
}
235+
};

0 commit comments

Comments
 (0)