Skip to content

[CDX-201] Tracking other related parameters#459

Merged
esezen merged 3 commits into
masterfrom
feat/CDX-201-track-window-parameters
Jun 30, 2026
Merged

[CDX-201] Tracking other related parameters#459
esezen merged 3 commits into
masterfrom
feat/CDX-201-track-window-parameters

Conversation

@Alexey-Pavlov

Copy link
Copy Markdown
Contributor

This pull request introduces support for using global window variables as fallback values for userId, testCells, and userSegments in the main query modules (search, browse, autocomplete, and recommendations) when the new trackWindowParameters option is enabled. It also ensures that the tracker module does not use these window globals, and adds comprehensive tests to validate this behavior. Additionally, a utility function for applying these window-based parameter getters is introduced and thoroughly tested.

@Alexey-Pavlov Alexey-Pavlov requested a review from a team June 5, 2026 18:27
…ing options and improve handling of window parameters
@Alexey-Pavlov Alexey-Pavlov marked this pull request as ready for review June 19, 2026 17:10
Copilot AI review requested due to automatic review settings June 19, 2026 17:10
@Alexey-Pavlov Alexey-Pavlov requested a review from a team as a code owner June 19, 2026 17:10
constructor-claude-bedrock[bot]

This comment was marked as outdated.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an opt-in trackWindowParameters client option that, when enabled in DOM environments, falls back to specific window globals for userId, testCells, and segments across the main query modules (search/browse/autocomplete/recommendations), while ensuring the tracker module does not use those window fallbacks. It also expands test coverage for these behaviors.

Changes:

  • Added helpers.applyWindowParameterGetters to implement window-global fallbacks for userId, testCells, and segments.
  • Added trackWindowParameters option wiring in the client constructor, and ensured tracker uses a separate options object.
  • Added recommendations support for testCells query params and added extensive tests for window fallback behavior across modules.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/utils/helpers.js Adds applyWindowParameterGetters to provide window-based fallback getters for user-related options.
src/types/index.d.ts Adds trackWindowParameters?: boolean to the public TS options type.
src/modules/recommendations.js Adds testCellsef-* query param support for recommendations requests.
src/constructorio.js Wires trackWindowParameters into client options and isolates tracker from window fallbacks.
spec/src/utils/helpers.js Adds unit tests for applyWindowParameterGetters behavior and priority rules.
spec/src/modules/tracker.js Adds tests ensuring tracker does not include window-global fallbacks, but still respects explicit option updates.
spec/src/modules/search.js Adds tests verifying search requests include/exclude window globals depending on trackWindowParameters.
spec/src/modules/recommendations.js Adds tests verifying recommendations requests include/exclude window globals depending on trackWindowParameters.
spec/src/modules/browse.js Adds tests verifying browse requests include/exclude window globals depending on trackWindowParameters.
spec/src/modules/autocomplete.js Adds tests verifying autocomplete requests include/exclude window globals depending on trackWindowParameters.
cspell.json Adds cnstrc to the dictionary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils/helpers.js
Comment on lines +393 to +398
applyWindowParameterGetters: (options) => {
const backing = {
userId: options.userId || undefined,
testCells: options.testCells || undefined,
segments: options.segments || undefined,
};
Comment thread src/constructorio.js Outdated
beaconMode: (beaconMode === false) ? false : true, // Defaults to 'true',
networkParameters: networkParameters || {},
humanityCheckLocation: humanityCheckLocation || 'session',
trackWindowParameters: trackWindowParameters || false,
Comment thread src/constructorio.js Outdated

this.trackerOptions = { ...this.options };

if (trackWindowParameters && helpers.canUseDOM()) {

@esezen esezen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1. Does the tracker need window params too?

Right now trackerOptions is snapshotted before applyWindowParameterGetters runs (src/constructorio.js:147), so the tracker module is deliberately excluded from window fallbacks — search/browse/autocomplete/recommendations get them, tracking events don't. Why are we doing this? I thought we wanted to include tracker in this implementation as well.

2. Renaming trackWindowParameters

The track prefix collides with the SDK's tracker vocabulary. What do you think about renaming it? Some options I thought about:

  • useWindowParameters
  • useDefaultWindowParameters
  • fallbackToWindowParameters

Comment thread src/constructorio.js Outdated
Comment thread src/constructorio.js Outdated
Comment thread src/utils/helpers.js
Comment thread src/utils/helpers.js Outdated
Comment thread src/constructorio.js Outdated
Comment thread spec/src/modules/search.js Outdated

@constructor-claude-bedrock constructor-claude-bedrock Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This PR adds useWindowParameters support to fall back to window.cnstrc globals for userId, testCells, and userSegments via property getters on the shared options object. The approach is creative but has a critical contradiction between the PR description and actual behavior, plus a few correctness and coverage issues.

Inline comments: 7 discussions added

Overall Assessment: ⚠️ Needs Work

expect(tracker.trackSessionStart()).to.equal(true);
});

it('Should include window globals in tracking requests when useWindowParameters is true', (done) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Important Issue: This test contradicts the PR description which says the tracker should NOT use window globals. See the comment on applyWindowParameterGetters for the full analysis.

Additionally, this test is missing a corresponding negative test ("Should NOT include window globals in tracking requests when useWindowParameters is false"), which all four other module test files have. Consistency here would verify the feature boundary behaves correctly across all modules.

});
});

it('Should include window global userId when useWindowParameters is true and options.userId is absent', (done) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: The search.js tests include a "Should prefer options.userId over window global when useWindowParameters is true" priority test (around line 185), but browse.js, autocomplete.js, and recommendations.js do not have equivalent priority tests for userId, testCells, and segments. For consistency and to fully verify that explicit options take precedence over window globals in all modules, consider adding these priority tests across all four module test files — or at minimum document that the priority is exclusively tested in search.js.

Comment thread src/constructorio.js
useWindowParameters: useWindowParameters === true,
};

if (useWindowParameters === true) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: applyWindowParameterGetters installs Object.defineProperty getters on this.options. Since this.options is a plain object, this works fine. However, calling applyWindowParameterGetters after this.options is fully constructed (line 149) means the initial/backing values captured in the getter closures for userId, segments, and testCells are whatever was set at construction time.

Note that testCells is pre-processed through helpers.toValidTestCells(testCells) on line 137 before the getter is installed. So backingTestCells is already filtered. This is consistent, but it would help to add a brief comment explaining this ordering dependency — e.g.:

// NOTE: applyWindowParameterGetters must be called AFTER this.options is
// fully initialized so the initial backing values (e.g. toValidTestCells)
// are captured correctly.
if (useWindowParameters === true) {
  helpers.applyWindowParameterGetters(this.options);
}

@Alexey-Pavlov

Copy link
Copy Markdown
Contributor Author

Hey @esezen! Thanks for the thoughtful review!
About the tracker module - It all makes sense, I think I just missed it, maybe I was hurrying to do it before my OOO. Thanks for catching it!
I renamed trackWindowParameters to useWindowParameters (it's more concise than fallbackToWindowParameters and avoids the track* collision), and made other necessary fixes and adjustments.
Could you please take a look when you get a chance?

@Alexey-Pavlov Alexey-Pavlov requested a review from esezen June 29, 2026 16:16

@esezen esezen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the changes!

@esezen esezen merged commit 638a552 into master Jun 30, 2026
14 of 15 checks passed
@esezen esezen deleted the feat/CDX-201-track-window-parameters branch June 30, 2026 14:55
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