Skip to content

Commit

Permalink
add google anaylytics events for search and change tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans authored and webpro committed Aug 28, 2023
1 parent a47606d commit 104093a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 9 additions & 4 deletions packages/apps/docs/src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IProps {
}

export const Search: FC<IProps> = ({ query, hasScroll, limitResults }) => {
const [, setTabName] = useState<string | undefined>();
const [tabName, setTabName] = useState<string | undefined>();
const {
metadata = [],
outputStream,
Expand All @@ -27,13 +27,18 @@ export const Search: FC<IProps> = ({ query, hasScroll, limitResults }) => {
.map(mapMatches);

useEffect(() => {
if (query !== undefined && query.trim() !== '') {
if (
query !== undefined &&
query.trim() !== '' &&
tabName !== undefined &&
tabName.trim() !== ''
) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
handleSubmit(query);
analyticsEvent(EVENT_NAMES['click:search'], { query });
analyticsEvent(EVENT_NAMES['click:search'], { query, tabName });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [query, handleSubmit]);
}, [query, tabName]);

const onTabSelect = (tabName: string): void => {
setTabName(tabName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ export const SearchResults: FC<IProps> = ({
};

useEffect(() => {
const value = localStorage.getItem(TABNAME);
setIsMounted(true);
if (value === null) return;
}, [setIsMounted]);

useEffect(() => {
const value = localStorage.getItem(TABNAME);
if (value === null) return;
setSelectedTabName(value);
onTabSelect(value);
}, [setSelectedTabName, setIsMounted, onTabSelect]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isMounted]);

if (!isMounted) return null;
return (
Expand Down

0 comments on commit 104093a

Please sign in to comment.