Skip to content

Commit

Permalink
Add event tracking to resources searching
Browse files Browse the repository at this point in the history
  • Loading branch information
DaoDaoNoCode committed Apr 21, 2022
1 parent b12ff21 commit c655974
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 c655974

Please sign in to comment.