Skip to content

Commit

Permalink
Merge pull request opendatahub-io#186 from DaoDaoNoCode/search-term-t…
Browse files Browse the repository at this point in the history
…racking

Add event tracking to resources searching
  • Loading branch information
anishasthana authored Apr 21, 2022
2 parents b12ff21 + c655974 commit a3b269e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions frontend/src/pages/learningCenter/LearningCenterToolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import * as _ from 'lodash';
import { useHistory } from 'react-router';
import {
Button,
Expand All @@ -24,6 +25,7 @@ import {
} from '@patternfly/react-icons';
import { removeQueryArgument, setQueryArgument } from '../../utilities/router';
import { useQueryParams } from '../../utilities/useQueryParams';
import { fireTrackingEvent } from '../../utilities/segmentIOUtils';
import {
SEARCH_FILTER_KEY,
DOC_SORT_KEY,
Expand Down Expand Up @@ -53,6 +55,16 @@ type LearningCenterToolbarProps = {
onToggleFiltersCollapsed: () => void;
};

// add 1 second debounce to fire the search event
// to avoid firing event with every single character input
const fireSearchedEvent = _.debounce((val: string) => {
if (val) {
fireTrackingEvent('Resource Searched', {
term: val,
});
}
}, 1000);

const LearningCenterToolbar: React.FC<LearningCenterToolbarProps> = ({
count,
totalCount,
Expand Down Expand Up @@ -89,6 +101,10 @@ const LearningCenterToolbar: React.FC<LearningCenterToolbarProps> = ({
setSearchInputText(searchQuery);
}, [searchQuery]);

React.useEffect(() => {
fireSearchedEvent(searchInputText);
}, [searchInputText]);

const onSortTypeSelect = React.useCallback(
(e) => {
setIsSortTypeDropdownOpen(false);
Expand Down

0 comments on commit a3b269e

Please sign in to comment.