Skip to content

Commit

Permalink
fix(headless/commerce): send clientId only when analytics are enabled (
Browse files Browse the repository at this point in the history
…#4217)

https://coveord.atlassian.net/browse/KIT-3312

Legally, one can only send data persisted in the browser (like the
clientId) when the user agrees to tracking (even for search queries, not
just for UA).

Most cases across the ui-kit project were already covered. I think these
are the only two spots left, but let me know 👍
  • Loading branch information
jpmarceau authored Jul 26, 2024
1 parent bcecc55 commit 323cede
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/headless/src/api/commerce/commerce-api-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface CurrencyParam {
}

export interface ClientIdParam {
clientId: string;
clientId?: string;
}

export interface ContextParam {
Expand Down
21 changes: 21 additions & 0 deletions packages/headless/src/features/commerce/common/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion packages/headless/src/features/commerce/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
? {
Expand Down

0 comments on commit 323cede

Please sign in to comment.