Skip to content

Commit

Permalink
feat(analytics): Track search events (#241)
Browse files Browse the repository at this point in the history
* 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 035fc9a.

* cleanup

* Refactor to a generic response transformation method

* Remove redundant `Array.from`

* Remove baseUri from slug

* fix: close modal on result click
  • Loading branch information
half0wl authored Apr 25, 2023
1 parent fceb70e commit 6d3fee0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/hooks/useDebouncedSearch.ts
Original file line number Diff line number Diff line change
@@ -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<Source, Result extends any> = (
src: SearchResponse<Source>,
) => Result;
Expand Down Expand Up @@ -102,6 +105,7 @@ export const useDebouncedSearch = <
}
try {
const response = await index.search<Response>(query, params);
trackGoal(FATHOM_SEARCH_PERFORMED_EVT_ID, 0);
setResults(transformResponse(response));
} catch (e) {
console.error(`Search for query "${query}" failed (${e})`);
Expand Down

0 comments on commit 6d3fee0

Please sign in to comment.