feat: add number of searches

Signed-off-by: Phil Berryman <phil@berryman.org.uk>
This commit is contained in:
Phil Berryman
2022-11-22 15:29:56 -08:00
parent db43cd1767
commit 29ebc43a0b
12 changed files with 43 additions and 11 deletions
@@ -23,14 +23,18 @@ import { useSearch } from '../../context';
*/
export const TrackSearch = ({ children }: { children: React.ReactChild }) => {
const analytics = useAnalytics();
const { term } = useSearch();
const { term, result } = useSearch();
const numberOfResults = result.value?.numberOfResults ?? undefined;
useEffect(() => {
if (term) {
// Capture analytics search event with search term provided as value
analytics.captureEvent('search', term);
analytics.captureEvent('search', term, {
value: numberOfResults,
});
}
}, [analytics, term]);
}, [analytics, term, numberOfResults]);
return <>{children}</>;
};