From 8226d670447372ebb69da367f08d9e158d12a339 Mon Sep 17 00:00:00 2001 From: David Brooke <38883189+dmbrooke@users.noreply.github.com> Date: Fri, 18 Aug 2023 14:13:12 -0400 Subject: [PATCH] Log correct exclusion analytics https://coveord.atlassian.net/browse/KIT-2684 --- .../search-parameter-analytics-actions.ts | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/headless/src/features/search-parameters/search-parameter-analytics-actions.ts b/packages/headless/src/features/search-parameters/search-parameter-analytics-actions.ts index d6424431b35..03cf561f1e8 100644 --- a/packages/headless/src/features/search-parameters/search-parameter-analytics-actions.ts +++ b/packages/headless/src/features/search-parameters/search-parameter-analytics-actions.ts @@ -3,6 +3,7 @@ import { logFacetClearAll, logFacetDeselect, logFacetSelect, + logFacetExclude, } from '../../features/facets/facet-set/facet-set-analytics-actions'; import {logSearchboxSubmit} from '../../features/query/query-analytics-actions'; import {SearchParameters} from '../../features/search-parameters/search-parameter-actions'; @@ -117,10 +118,16 @@ function logFacetAnalyticsAction( const addedIds = newIds.filter((id) => !previousIds.includes(id)); if (addedIds.length) { const facetId = addedIds[0]; - return logFacetSelect({ - facetId, - facetValue: newFacets[facetId][0], - }); + const facetValue = newFacets[facetId][0]; + return facetValue === 'selected' + ? logFacetSelect({ + facetId, + facetValue: facetValue, + }) + : logFacetExclude({ + facetId, + facetValue: facetValue, + }); } const facetIdWithDifferentValues = newIds.find((key) => @@ -140,10 +147,15 @@ function logFacetAnalyticsAction( ); if (addedValues.length) { - return logFacetSelect({ - facetId: facetIdWithDifferentValues, - facetValue: addedValues[0], - }); + return addedValues[0] === 'selected' + ? logFacetSelect({ + facetId: facetIdWithDifferentValues, + facetValue: addedValues[0], + }) + : logFacetExclude({ + facetId: facetIdWithDifferentValues, + facetValue: addedValues[0], + }); } const removedValues = previousValues.filter(