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

feat(headless SSR commerce): Allow setting analytics 'capture' property through navigator provider #4995

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

fbeaudoincoveo
Copy link
Contributor

@fbeaudoincoveo fbeaudoincoveo commented Feb 19, 2025

I'm also including a more full-fledged implementation of the clientId in the Remix SSR sample.

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

@jpmarceau I'm adding you as a reviewer mainly for the Remix SSR sample part (although there's also a bit of new reference docs in this PR).

request.headers.get('Cookie')
);
const clientId = clientIdCookie ?? randomUUID();
const clientId = await getClientId(request);
Copy link
Contributor Author

@fbeaudoincoveo fbeaudoincoveo Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • TODO: Implement client ID with cookie in NextJS sample

Copy link

github-actions bot commented Feb 19, 2025

Pull Request Report

PR Title

❌ Title should follow the conventional commit spec:
<type>(optional scope): <description>

Example: feat(headless): add result-list controller

Live demo links

Bundle Size

File Old (kb) New (kb) Change (%)
case-assist 243.7 243.7 0
commerce 355 355.1 0
search 415 415.1 0
insight 406.2 406.3 0
recommendation 255.9 255.9 0
ssr 408.8 408.9 0
ssr-commerce 372.7 372.8 0

@@ -25,7 +25,9 @@ export const fromAnalyticsStateToAnalyticsParams = (
...(s.userDisplayName && {userDisplayName: s.userDisplayName}),
...(s.deviceId && {deviceId: s.deviceId}),
...(s.trackingId && {trackingId: s.trackingId}),
...{capture: true},
...{
capture: navigatorContext.capture ?? navigatorContext.clientId !== '',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the clientId is '', requests will fail, so this is a better fallback than true IMO.

const totalItemsInCart = await externalCartService.getTotalCount();
const cookie = await coveo_visitorId.parse(request.headers.get('Cookie'));
Copy link
Contributor Author

@fbeaudoincoveo fbeaudoincoveo Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a pretty weak implementation that didn't take into account the possibility that using the cookie could be prevented by the user's privacy settings.

We're now setting the cookie conditionally in each route that leverages Coveo instead.

Copy link
Collaborator

@louis-bompart louis-bompart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, would take some UT tho

*
* Must be set left undefined or set to `false` if the `clientId` is an empty string, otherwise requests will fail.
*
* Should also be set to `false` to comply with regulations if the user has somehow indicated that they do not wish to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regulations varies depending on regions and all, let's not provide legal advices and focus on what the parameter does only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpmarceau what do you think? Is there some documentation we could/should link to instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could link to https://docs.coveo.com/en/3348
But I think it would be fair to do as Louis suggests, only stating what the param does. I would expect readers to consult the documentation site rather than reference documentation for such considerations.

@@ -151,7 +151,8 @@ export const buildQuerySuggestRequest = (
? {referrer: navigatorContext.referrer}
: {}),
},
capture: state.configuration.analytics.enabled,
capture:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be tested (UT)

@@ -25,7 +25,9 @@ export const fromAnalyticsStateToAnalyticsParams = (
...(s.userDisplayName && {userDisplayName: s.userDisplayName}),
...(s.deviceId && {deviceId: s.deviceId}),
...(s.trackingId && {trackingId: s.trackingId}),
...{capture: true},
...{
capture: navigatorContext.capture ?? navigatorContext.clientId !== '',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be tested (UT)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants