Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ep): do not send actionCause w/ breadcrumbResetAll #4207

Merged
merged 13 commits into from
Jul 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import {facetResponseActiveValuesSelector} from '../../features/facets/facet-set
import {facetSetReducer as facetSet} from '../../features/facets/facet-set/facet-set-slice';
import {FacetSlice} from '../../features/facets/facet-set/facet-set-state';
import {FacetValue} from '../../features/facets/facet-set/interfaces/response';
import {
breadcrumbResetAll,
logClearBreadcrumbs,
} from '../../features/facets/generic/facet-generic-analytics-actions';
import {logClearBreadcrumbs} from '../../features/facets/generic/facet-generic-analytics-actions';
import {
toggleExcludeDateFacetValue,
toggleSelectDateFacetValue,
Expand Down Expand Up @@ -393,7 +390,6 @@ export function buildBreadcrumbManager(
dispatch(
executeSearch({
legacy: logClearBreadcrumbs(),
next: breadcrumbResetAll(),
})
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {logFacetBreadcrumb} from '../../../features/facets/facet-set/facet-set-i
import {facetResponseActiveValuesSelector} from '../../../features/facets/facet-set/facet-set-selectors';
import {facetSetReducer as facetSet} from '../../../features/facets/facet-set/facet-set-slice';
import {FacetSlice} from '../../../features/facets/facet-set/facet-set-state';
import {breadcrumbResetAll} from '../../../features/facets/generic/facet-generic-analytics-actions';
import {logClearBreadcrumbs} from '../../../features/facets/generic/facet-generic-insight-analytics-actions';
import {
toggleExcludeDateFacetValue,
Expand Down Expand Up @@ -296,7 +295,6 @@ export function buildBreadcrumbManager(
dispatch(
executeSearch({
legacy: logClearBreadcrumbs(),
next: breadcrumbResetAll(),
})
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
facetClearAll,
facetDeselect,
facetSelect,
facetShowLess,
facetShowMore,
facetUpdateSort,
} from '../../../../features/facets/facet-set/facet-set-analytics-actions';
import {
Expand Down Expand Up @@ -141,7 +139,6 @@ export function buildCategoryFacet(
dispatch(
fetchFacetValues({
legacy: logFacetShowMore(getFacetId()),
next: facetShowMore(),
})
);
},
Expand All @@ -151,7 +148,6 @@ export function buildCategoryFacet(
dispatch(
fetchFacetValues({
legacy: logFacetShowLess(getFacetId()),
next: facetShowLess(),
})
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {FacetValueState} from '../../../../features/facets/facet-api/value';
import {specificFacetSearchSetReducer as facetSearchSet} from '../../../../features/facets/facet-search-set/specific/specific-facet-search-set-slice';
import {
facetClearAll,
facetShowLess,
facetShowMore,
facetUpdateSort,
} from '../../../../features/facets/facet-set/facet-set-analytics-actions';
import {
Expand Down Expand Up @@ -173,7 +171,6 @@ export function buildFacet(engine: InsightEngine, props: FacetProps): Facet {
dispatch(
fetchFacetValues({
legacy: logFacetShowMore(getFacetId()),
next: facetShowMore(),
})
);
},
Expand All @@ -183,7 +180,6 @@ export function buildFacet(engine: InsightEngine, props: FacetProps): Facet {
dispatch(
fetchFacetValues({
legacy: logFacetShowLess(getFacetId()),
next: facetShowLess(),
})
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import {
logClearRecentQueries,
logRecentQueryClick,
recentQueryClick,
} from '../../features/recent-queries/recent-queries-analytics-actions';
import {recentQueriesReducer as recentQueries} from '../../features/recent-queries/recent-queries-slice';
import {
Expand Down Expand Up @@ -218,7 +217,6 @@ export function buildRecentQueriesList(
dispatch(
executeSearch({
legacy: logRecentQueryClick(),
next: recentQueryClick(),
})
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,3 @@ export const facetUnexclude = (): SearchAction => ({
export const breadcrumbFacet = (): SearchAction => ({
actionCause: SearchPageEvents.breadcrumbFacet,
});

export const facetShowLess = (): SearchAction => ({
actionCause: SearchPageEvents.facetShowLess,
});

export const facetShowMore = (): SearchAction => ({
actionCause: SearchPageEvents.facetShowMore,
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import {
makeAnalyticsAction,
LegacySearchAction,
} from '../../analytics/analytics-utils';
import {SearchPageEvents} from '../../analytics/search-action-cause';
import {SearchAction} from '../../search/search-actions';

//TODO: KIT-2859
export const logClearBreadcrumbs = (): LegacySearchAction =>
makeAnalyticsAction('analytics/facet/deselectAllBreadcrumbs', (client) => {
return client.makeBreadcrumbResetAll();
});

export const breadcrumbResetAll = (): SearchAction => ({
actionCause: SearchPageEvents.breadcrumbResetAll,
});
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ export const executeSearch = createAsyncThunk<
config: AsyncThunkConfig
) => {
const state = config.getState();
if (
state.configuration.analytics.analyticsMode === 'legacy' ||
!analyticsAction.next
) {
if (state.configuration.analytics.analyticsMode === 'legacy') {
return legacyExecuteSearch(state, config, analyticsAction.legacy);
}

Expand All @@ -127,7 +124,9 @@ export const executeSearch = createAsyncThunk<
...config,
});

const eventDescription = buildEventDescription(analyticsAction.next);
const eventDescription = analyticsAction.next
? buildEventDescription(analyticsAction.next)
: undefined;
const request = await buildInsightSearchRequest(state, eventDescription);
const fetched = await processor.fetchFromAPI(request);

Expand Down Expand Up @@ -208,22 +207,15 @@ export const fetchFacetValues = createAsyncThunk<
) => {
const state = config.getState();

if (
state.configuration.analytics.analyticsMode === 'legacy' ||
!analyticsAction.next
) {
if (state.configuration.analytics.analyticsMode === 'legacy') {
return legacyFetchFacetValues(state, config, analyticsAction.legacy);
}

const processor = new AsyncInsightSearchThunkProcessor({
...config,
});

const eventDescription = buildEventDescription(analyticsAction.next);
const request = await buildInsightFetchFacetValuesRequest(
state,
eventDescription
);
const request = await buildInsightFetchFacetValuesRequest(state);
const fetched = await processor.fetchFromAPI(request);

return await processor.process(fetched);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
CustomAction,
LegacySearchAction,
} from '../analytics/analytics-utils';
import {SearchPageEvents} from '../analytics/search-action-cause';
import {SearchAction} from '../search/search-actions';

export const logClearRecentQueries = (): CustomAction =>
makeAnalyticsAction('analytics/recentQueries/clear', (client) => {
Expand All @@ -16,7 +14,3 @@ export const logRecentQueryClick = (): LegacySearchAction =>
makeAnalyticsAction('analytics/recentQueries/click', (client) => {
return client.makeRecentQueryClick();
});

export const recentQueryClick = (): SearchAction => ({
actionCause: SearchPageEvents.recentQueryClick,
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {
import {buildSearchRequest} from './search-request';

export interface AnalyticsAction {
actionCause: string;
actionCause?: string;
}

export type StateNeededByExecuteSearch = ConfigurationSection &
Expand Down
22 changes: 8 additions & 14 deletions packages/headless/src/features/search/search-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,13 @@ export const executeSearch = createAsyncThunk<
'search/executeSearch',
async (searchAction: TransitiveSearchAction, config) => {
const state = config.getState();
if (
state.configuration.analytics.analyticsMode === 'legacy' ||
!searchAction.next
) {
if (state.configuration.analytics.analyticsMode === 'legacy') {
return legacyExecuteSearch(state, config, searchAction.legacy);
}
addEntryInActionsHistory(state);
const analyticsAction = buildSearchReduxAction(searchAction.next);
const analyticsAction = searchAction.next
? buildSearchReduxAction(searchAction.next)
: undefined;

const request = await buildSearchRequest(
state,
Expand All @@ -127,7 +126,7 @@ export const executeSearch = createAsyncThunk<

const processor = new AsyncSearchThunkProcessor<
ReturnType<typeof config.rejectWithValue>
>({...config, analyticsAction});
>({...config, analyticsAction: analyticsAction ?? {}});

const fetched = await processor.fetchFromAPI(request, {
origin: 'mainSearch',
Expand Down Expand Up @@ -209,22 +208,17 @@ export const fetchFacetValues = createAsyncThunk<
'search/fetchFacetValues',
async (searchAction: TransitiveSearchAction, config) => {
const state = config.getState();
if (
state.configuration.analytics.analyticsMode === 'legacy' ||
!searchAction.next
) {
if (state.configuration.analytics.analyticsMode === 'legacy') {
return legacyExecuteSearch(state, config, searchAction.legacy);
}
const analyticsAction = buildSearchReduxAction(searchAction.next);

const processor = new AsyncSearchThunkProcessor<
ReturnType<typeof config.rejectWithValue>
>({...config, analyticsAction});
>({...config, analyticsAction: {}});

const request = await buildFetchFacetValuesRequest(
state,
config.extra.navigatorContext,
analyticsAction
config.extra.navigatorContext
);
const fetched = await processor.fetchFromAPI(request, {
origin: 'facetValues',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ import {
logFacetDeselect,
logFacetExclude,
logFacetSelect,
logFacetShowLess,
logFacetShowMore,
logFacetUpdateSort,
} from '../features/facets/facet-set/facet-set-analytics-actions';
import {FacetSortCriterion} from '../features/facets/facet-set/interfaces/request';
import {
breadcrumbResetAll,
logClearBreadcrumbs,
} from '../features/facets/generic/facet-generic-analytics-actions';
import {logClearBreadcrumbs} from '../features/facets/generic/facet-generic-analytics-actions';
import {registerDateFacet} from '../features/facets/range-facets/date-facet-set/date-facet-actions';
import {
dateBreadcrumbFacet,
Expand Down Expand Up @@ -82,15 +81,15 @@ import {
logSearchboxSubmit,
searchboxSubmit,
} from '../features/query/query-analytics-actions';
import {
logRecentQueryClick,
recentQueryClick,
} from '../features/recent-queries/recent-queries-analytics-actions';
import {logRecentQueryClick} from '../features/recent-queries/recent-queries-analytics-actions';
import {
logRecommendationUpdate,
recommendationInterfaceLoad,
} from '../features/recommendation/recommendation-analytics-actions';
import {executeSearch} from '../features/search/search-actions';
import {
executeSearch,
fetchFacetValues,
} from '../features/search/search-actions';
import {
logResultsSort,
resultsSort,
Expand Down Expand Up @@ -275,14 +274,13 @@ describe('Analytics Search Migration', () => {
it('analytics/facet/deselectAllBreadcrumbs', async () => {
const action = executeSearch({
legacy: logClearBreadcrumbs(),
next: breadcrumbResetAll(),
});

legacySearchEngine.dispatch(action);
nextSearchEngine.dispatch(action);
await clearMicrotaskQueue();

assertNextEqualsLegacy(callSpy);
assertNextEqualsLegacy(callSpy, [...excludedBaseProperties, 'actionCause']);
});

it('analytics/facet/exclude', async () => {
Expand Down Expand Up @@ -845,14 +843,13 @@ describe('Analytics Search Migration', () => {
it('analytics/recentQueries/click', async () => {
const action = executeSearch({
legacy: logRecentQueryClick(),
next: recentQueryClick(),
});

legacySearchEngine.dispatch(action);
nextSearchEngine.dispatch(action);
await clearMicrotaskQueue();

assertNextEqualsLegacy(callSpy);
assertNextEqualsLegacy(callSpy, [...excludedBaseProperties, 'actionCause']);
});

it('analytics/interface/change', async () => {
Expand Down Expand Up @@ -996,4 +993,28 @@ describe('Analytics Search Migration', () => {

assertNextEqualsLegacy(callSpy);
});

it('analytics/facet/showMore', async () => {
const action = fetchFacetValues({
legacy: logFacetShowMore(ANY_FACET_ID),
});

legacySearchEngine.dispatch(action);
nextSearchEngine.dispatch(action);
await clearMicrotaskQueue();

assertNextEqualsLegacy(callSpy, [...excludedBaseProperties, 'actionCause']);
});

it('analytics/facet/showLess', async () => {
const action = fetchFacetValues({
legacy: logFacetShowLess(ANY_FACET_ID),
});

legacySearchEngine.dispatch(action);
nextSearchEngine.dispatch(action);
await clearMicrotaskQueue();

assertNextEqualsLegacy(callSpy, [...excludedBaseProperties, 'actionCause']);
});
});
Loading
Loading