From 6d3fee0b0a72a1ce33fdf56b2bb1688757154465 Mon Sep 17 00:00:00 2001 From: Ray Chen Date: Tue, 25 Apr 2023 16:30:09 +0800 Subject: [PATCH] feat(analytics): Track search events (#241) * Implement new search UI * Move "no results" into its own component * re-lock dependencies * Refactor: Move search logic into reusable hooks * Refactor: clean up, combine useSearchIndex * Refactor: Separate QueryInput, add ability to clear results * Cleanup * Tweak UI * Cleanup: Remove unused types * feat(analytics): Track search events * Move searchParams out; lower debounce ms * UI: Make "Clear" button smaller * Remove OpenSearchModalButton from mobile nav * Revert "Remove OpenSearchModalButton from mobile nav" This reverts commit 035fc9ae94fddf30c87e5195506df4ecf3ddfbfb. * cleanup * Refactor to a generic response transformation method * Remove redundant `Array.from` * Remove baseUri from slug * fix: close modal on result click --- src/hooks/useDebouncedSearch.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hooks/useDebouncedSearch.ts b/src/hooks/useDebouncedSearch.ts index f69d3f8d3..b5be87878 100644 --- a/src/hooks/useDebouncedSearch.ts +++ b/src/hooks/useDebouncedSearch.ts @@ -1,7 +1,10 @@ import { Search } from "@/types"; +import { trackGoal } from "fathom-client"; import { MeiliSearch, SearchParams, SearchResponse } from "meilisearch"; import { useCallback, useEffect, useMemo, useState } from "react"; +const FATHOM_SEARCH_PERFORMED_EVT_ID = "IMSTAYP4"; + type Transformer = ( src: SearchResponse, ) => Result; @@ -102,6 +105,7 @@ export const useDebouncedSearch = < } try { const response = await index.search(query, params); + trackGoal(FATHOM_SEARCH_PERFORMED_EVT_ID, 0); setResults(transformResponse(response)); } catch (e) { console.error(`Search for query "${query}" failed (${e})`);