From 15015f78f3067ba59e2700b46b131d2c82157b5d Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Thu, 7 Sep 2023 08:21:37 +0200 Subject: [PATCH] feat: Plausible search (#4625) --- .../component/common/Search/Search.test.tsx | 5 +-- .../SearchDescription/SearchDescription.tsx | 4 ++- .../SearchSuggestions/SearchSuggestions.tsx | 35 +++++++++++++++---- frontend/src/hooks/usePlausibleTracker.ts | 3 +- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/frontend/src/component/common/Search/Search.test.tsx b/frontend/src/component/common/Search/Search.test.tsx index 200d4828e0..9dde31f3a8 100644 --- a/frontend/src/component/common/Search/Search.test.tsx +++ b/frontend/src/component/common/Search/Search.test.tsx @@ -21,10 +21,7 @@ const testDisplayComponent = ( ); test('should read saved query from local storage', async () => { - const { value, setValue } = createLocalStorage( - 'Search:localStorageId:v1', - {} - ); + const { setValue } = createLocalStorage('Search:localStorageId:v1', {}); setValue({ query: 'oldquery', }); diff --git a/frontend/src/component/common/Search/SearchSuggestions/SearchDescription/SearchDescription.tsx b/frontend/src/component/common/Search/SearchSuggestions/SearchDescription/SearchDescription.tsx index e25daf1d66..333ccd5691 100644 --- a/frontend/src/component/common/Search/SearchSuggestions/SearchDescription/SearchDescription.tsx +++ b/frontend/src/component/common/Search/SearchSuggestions/SearchDescription/SearchDescription.tsx @@ -58,7 +58,9 @@ export const SearchDescription: VFC = ({ {filter.values.join(',')} {' '} in {filter.header}. Options:{' '} - {filter.options.slice(0, 10).join(', ')} + {[...new Set(filter.options)] + .slice(0, 10) + .join(', ')}

))} diff --git a/frontend/src/component/common/Search/SearchSuggestions/SearchSuggestions.tsx b/frontend/src/component/common/Search/SearchSuggestions/SearchSuggestions.tsx index 5c10f57ac4..6d16ccc77a 100644 --- a/frontend/src/component/common/Search/SearchSuggestions/SearchSuggestions.tsx +++ b/frontend/src/component/common/Search/SearchSuggestions/SearchSuggestions.tsx @@ -13,6 +13,7 @@ import { SearchInstructions, StyledCode, } from './SearchInstructions/SearchInstructions'; +import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; const StyledPaper = styled(Paper)(({ theme }) => ({ position: 'absolute', @@ -55,13 +56,12 @@ interface SearchSuggestionsProps { const quote = (item: string) => (item.includes(' ') ? `"${item}"` : item); -const randomIndex = (arr: any[]) => Math.floor(Math.random() * arr.length); - export const SearchSuggestions: VFC = ({ getSearchContext, onSuggestion, savedQuery, }) => { + const { trackEvent } = usePlausibleTracker(); const searchContext = getSearchContext(); const filters = getFilterableColumns(searchContext.columns) @@ -116,7 +116,14 @@ export const SearchSuggestions: VFC = ({ onSuggestion(savedQuery || '')} + onClick={() => { + onSuggestion(savedQuery || ''); + trackEvent('search-filter-suggestions', { + props: { + eventType: 'saved query', + }, + }); + }} > {savedQuery} @@ -146,7 +153,14 @@ export const SearchSuggestions: VFC = ({ searchableColumnsString={ searchableColumnsString } - onClick={onSuggestion} + onClick={suggestion => { + onSuggestion(suggestion); + trackEvent('search-filter-suggestions', { + props: { + eventType: 'filter', + }, + }); + }} /> } /> @@ -159,9 +173,16 @@ export const SearchSuggestions: VFC = ({ show="Combine filters and search: " /> - onSuggestion(selectedFilter + ' ' + suggestedTextSearch) - } + onClick={() => { + onSuggestion( + selectedFilter + ' ' + suggestedTextSearch + ); + trackEvent('search-filter-suggestions', { + props: { + eventType: 'search and filter', + }, + }); + }} > {selectedFilter}{' '} {suggestedTextSearch} diff --git a/frontend/src/hooks/usePlausibleTracker.ts b/frontend/src/hooks/usePlausibleTracker.ts index 1136c06b67..4e8581e2d4 100644 --- a/frontend/src/hooks/usePlausibleTracker.ts +++ b/frontend/src/hooks/usePlausibleTracker.ts @@ -43,7 +43,8 @@ export type CustomEvents = | 'strategy-add' | 'playground' | 'feature-type-edit' - | 'strategy-variants'; + | 'strategy-variants' + | 'search-filter-suggestions'; export const usePlausibleTracker = () => { const plausible = useContext(PlausibleContext);