diff --git a/packages/headless/src/api/commerce/commerce-api-params.ts b/packages/headless/src/api/commerce/commerce-api-params.ts index f0f6b44a6a2..ecb58980b0d 100644 --- a/packages/headless/src/api/commerce/commerce-api-params.ts +++ b/packages/headless/src/api/commerce/commerce-api-params.ts @@ -18,7 +18,7 @@ export interface CurrencyParam { } export interface ClientIdParam { - clientId: string; + clientId?: string; } export interface ContextParam { diff --git a/packages/headless/src/features/commerce/common/actions.test.ts b/packages/headless/src/features/commerce/common/actions.test.ts index fc325280518..0dbc458996d 100644 --- a/packages/headless/src/features/commerce/common/actions.test.ts +++ b/packages/headless/src/features/commerce/common/actions.test.ts @@ -245,6 +245,27 @@ describe('commerce common actions', () => { } ); + it.each([true, false])( + 'sets the clientId conditionally upon the analytics configuration', + (analyticsEnabled) => { + state.configuration.analytics.enabled = analyticsEnabled; + + const request = Actions.buildCommerceAPIRequest( + state, + navigatorContext + ); + + expect(mockedBuildBaseCommerceAPIRequest).toHaveBeenCalledWith( + state, + navigatorContext + ); + + expect(request.clientId).toEqual( + analyticsEnabled ? 'client_id' : undefined + ); + } + ); + describe('given a state that has the commerceFacetSet and manualNumericFacetSet', () => { let facet1: CommerceFacetSlice; let manualFacet1: ManualNumericFacetSetSlice; diff --git a/packages/headless/src/features/commerce/common/actions.ts b/packages/headless/src/features/commerce/common/actions.ts index ba26a3e7c2b..bc62e94cf9c 100644 --- a/packages/headless/src/features/commerce/common/actions.ts +++ b/packages/headless/src/features/commerce/common/actions.ts @@ -65,7 +65,9 @@ export const buildBaseCommerceAPIRequest = ( organizationId: state.configuration.organizationId, trackingId: state.configuration.analytics.trackingId, ...restOfContext, - clientId: navigatorContext.clientId, + ...(state.configuration.analytics.enabled + ? {clientId: navigatorContext.clientId} + : {}), context: { ...(navigatorContext.userAgent ? { diff --git a/packages/headless/src/features/commerce/query-suggest/query-suggest-actions.ts b/packages/headless/src/features/commerce/query-suggest/query-suggest-actions.ts index efb65959ce3..469ec99a8f9 100644 --- a/packages/headless/src/features/commerce/query-suggest/query-suggest-actions.ts +++ b/packages/headless/src/features/commerce/query-suggest/query-suggest-actions.ts @@ -129,7 +129,9 @@ export const buildQuerySuggestRequest = ( trackingId: state.configuration.analytics.trackingId, query: state.querySet[id], ...restOfContext, - clientId: navigatorContext.clientId, + ...(state.configuration.analytics.enabled + ? {clientId: navigatorContext.clientId} + : {}), context: { ...(navigatorContext.userAgent ? {