From 223609792abad296df77f5ed76dee0d4775ee1c4 Mon Sep 17 00:00:00 2001 From: Tim Hostetler <6970899+thostetler@users.noreply.github.com> Date: Wed, 1 Nov 2023 04:10:05 -0400 Subject: [PATCH] add analytics call for facets --- src/components/SearchFacet/SearchFacet.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/SearchFacet/SearchFacet.tsx b/src/components/SearchFacet/SearchFacet.tsx index 079b5331b..8e072bb11 100644 --- a/src/components/SearchFacet/SearchFacet.tsx +++ b/src/components/SearchFacet/SearchFacet.tsx @@ -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; @@ -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])); @@ -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 = () => {