Skip to content

Commit

Permalink
add analytics call for facets
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler committed Nov 1, 2023
1 parent a165002 commit 2236097
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/SearchFacet/SearchFacet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { CSSProperties, MouseEventHandler, ReactElement, useCallback, useEffect,
import { facetConfig } from './config';
import { applyFiltersToQuery } from './helpers';
import { FacetLogic, OnFilterArgs, SearchFacetID } from './types';
import { useGTMDispatch } from '@elgorditosalsero/react-gtm-hook';

export interface ISearchFacetProps extends AccordionItemProps {
field: FacetField;
Expand All @@ -62,6 +63,7 @@ const querySelector = (state: AppState) => omit(['fl', 'start', 'rows'], state.l

export const SearchFacet = (props: ISearchFacetProps): ReactElement => {
const store = useStoreApi();
const sendDataToGTM = useGTMDispatch();
const setFacetState = useStore((state) => state.setSearchFacetState);
const facets = useStore((state) => state.settings.searchFacets.order);
const hiddenFacets = useStore(useCallback((state) => state.getHiddenSearchFacets(), [facets]));
Expand Down Expand Up @@ -96,6 +98,11 @@ export const SearchFacet = (props: ISearchFacetProps): ReactElement => {
const handleOnFilter = (filterArgs: OnFilterArgs) => {
const query = store.getState().latestQuery;
onQueryUpdate(applyFiltersToQuery({ ...filterArgs, query }));
sendDataToGTM({
event: 'facet_applied',
facet_field: filterArgs.field,
facet_logic: filterArgs.logic,
});
};

const handleHideClick = () => {
Expand Down

0 comments on commit 2236097

Please sign in to comment.