mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-11-20 02:21:15 +01:00
fix(analytics): debounce PostHog "no icons found" event tracking
- Use debouncedQuery instead of searchQuery to prevent premature events - Add 500ms debounce delay before sending PostHog events - Require minimum 2 characters to avoid false positives from single character searches - Fix bug where events fired before filtering completed
This commit is contained in:
@@ -38,6 +38,7 @@ export function IconSearch({ icons }: IconSearchProps) {
|
|||||||
const [selectedCategories, setSelectedCategories] = useState<string[]>(initialCategories ?? [])
|
const [selectedCategories, setSelectedCategories] = useState<string[]>(initialCategories ?? [])
|
||||||
const [sortOption, setSortOption] = useState<SortOption>(initialSort)
|
const [sortOption, setSortOption] = useState<SortOption>(initialSort)
|
||||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null)
|
const timeoutRef = useRef<NodeJS.Timeout | null>(null)
|
||||||
|
const noIconsFoundTimeoutRef = useRef<NodeJS.Timeout | null>(null)
|
||||||
const { resolvedTheme } = useTheme()
|
const { resolvedTheme } = useTheme()
|
||||||
const [isLazyRequestSubmitted, setIsLazyRequestSubmitted] = useState(false)
|
const [isLazyRequestSubmitted, setIsLazyRequestSubmitted] = useState(false)
|
||||||
|
|
||||||
@@ -162,19 +163,36 @@ export function IconSearch({ icons }: IconSearchProps) {
|
|||||||
if (timeoutRef.current) {
|
if (timeoutRef.current) {
|
||||||
clearTimeout(timeoutRef.current)
|
clearTimeout(timeoutRef.current)
|
||||||
}
|
}
|
||||||
|
if (noIconsFoundTimeoutRef.current) {
|
||||||
|
clearTimeout(noIconsFoundTimeoutRef.current)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (filteredIcons.length === 0 && searchQuery) {
|
if (noIconsFoundTimeoutRef.current) {
|
||||||
console.log("no icons found", {
|
clearTimeout(noIconsFoundTimeoutRef.current)
|
||||||
query: searchQuery,
|
|
||||||
})
|
|
||||||
posthog.capture("no icons found", {
|
|
||||||
query: searchQuery,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}, [filteredIcons, searchQuery])
|
|
||||||
|
if (filteredIcons.length === 0 && debouncedQuery.trim().length >= 2) {
|
||||||
|
noIconsFoundTimeoutRef.current = setTimeout(() => {
|
||||||
|
if (filteredIcons.length === 0 && debouncedQuery.trim().length >= 2) {
|
||||||
|
console.log("no icons found", {
|
||||||
|
query: debouncedQuery,
|
||||||
|
})
|
||||||
|
posthog.capture("no icons found", {
|
||||||
|
query: debouncedQuery,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (noIconsFoundTimeoutRef.current) {
|
||||||
|
clearTimeout(noIconsFoundTimeoutRef.current)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [filteredIcons, debouncedQuery])
|
||||||
|
|
||||||
if (!searchParams) return null
|
if (!searchParams) return null
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user