Skip to content

[REM-3439] Viewable impressions tracking#456

Merged
esezen merged 5 commits into
masterfrom
REM-3439/results-impression-tracking
Jun 11, 2026
Merged

[REM-3439] Viewable impressions tracking#456
esezen merged 5 commits into
masterfrom
REM-3439/results-impression-tracking

Conversation

@ZSnake

@ZSnake ZSnake commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Viewable impressions tracking

For context, we're introducing viewable impressions tracking for Sponsored listings to get a better outlook on wether a sponsored product was actually viewed by the end user. This PR will introduce

  • trackResultsImpressionView to the tracker.js
  • Necessary types to tracker.d.ts
  • Tests

References

@ZSnake ZSnake requested review from a team and esezen June 3, 2026 17:09

@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.

Looking good, I left two small comments

Comment thread src/modules/tracker.js Outdated
Comment thread spec/src/modules/tracker.js
@ZSnake ZSnake requested a review from esezen June 10, 2026 10:11
@ZSnake ZSnake marked this pull request as ready for review June 10, 2026 10:11
@ZSnake ZSnake requested a review from a team as a code owner June 10, 2026 10:11
Copilot AI review requested due to automatic review settings June 10, 2026 10:11
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

Adds a new Tracker API for “results impression view” events to support viewable impressions tracking, including TypeScript typings and accompanying unit tests.

Changes:

  • Added trackResultsImpressionView to src/modules/tracker.js to POST /v2/behavioral_action/impression_view.
  • Added trackResultsImpressionView typings to src/types/tracker.d.ts.
  • Added a comprehensive test suite for trackResultsImpressionView in spec/src/modules/tracker.js.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/types/tracker.d.ts Adds the new trackResultsImpressionView method signature to the Tracker type definitions.
src/modules/tracker.js Implements the trackResultsImpressionView tracking call and request construction.
spec/src/modules/tracker.js Adds unit tests validating request/response behavior for the new tracking method.

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

Comment thread src/modules/tracker.js
Comment thread spec/src/modules/tracker.js
Comment on lines +15716 to +15728
tracker.on('success', (responseParams) => {
const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Body
expect(fetchSpy).to.have.been.called;
validateOriginReferrer(bodyParams);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message').to.equal('ok');

done();
});
Comment on lines +15745 to +15757
tracker.on('success', (responseParams) => {
const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Body
expect(fetchSpy).to.have.been.called;
expect(bodyParams).to.not.have.property('origin_referrer');

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message').to.equal('ok');

done();
});
@ZSnake ZSnake force-pushed the REM-3439/results-impression-tracking branch from 981c20f to 4282415 Compare June 10, 2026 15:04
constructor-claude-bedrock[bot]

This comment was marked as outdated.

@ZSnake ZSnake force-pushed the REM-3439/results-impression-tracking branch from 4282415 to b3b3532 Compare June 10, 2026 15:08
constructor-claude-bedrock[bot]

This comment was marked as outdated.

constructor-claude-bedrock[bot]

This comment was marked as 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 introduces trackResultsImpressionView for viewable impressions tracking of Sponsored listings, adding the tracker method, TypeScript types, and tests. The implementation is clean and consistent with existing patterns, but has a few issues worth addressing.

Inline comments: 4 discussions added

Overall Assessment: ⚠️ Needs Work

Comment thread src/types/tracker.d.ts

trackResultsImpressionView(
parameters: {
items: (Required<Pick<ItemTracked, 'itemId' | 'itemName'>> & Omit<ItemTracked, 'itemId' | 'itemName' | 'price'>)[];

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 type expression Required<Pick<ItemTracked, 'itemId' | 'itemName'>> & Omit<ItemTracked, 'itemId' | 'itemName' | 'price'> is functionally correct but difficult to read at a glance. Since ItemTracked already has all these fields defined, consider defining a dedicated ResultsImpressionViewItem interface in src/types/index.d.ts for clarity:

export interface ResultsImpressionViewItem {
  itemId: string;        // required
  itemName: string;      // required
  variationId?: string;
  slCampaignId?: string;
  slCampaignOwner?: string;
}

This also makes the public API surface more self-documenting.

expect(tracker.trackResultsImpressionView({ items: [{ itemId: '1' }] })).to.be.an('error');
});

it('Should throw an error when items contains non-object entries', () => {

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 test suite covers most error and happy-path scenarios well. However, there is no test verifying that slCampaignId and slCampaignOwner fields are correctly serialized to sl_campaign_id and sl_campaign_owner in the request body when passed as optional item properties. While the first required-parameters test does include these fields and checks deep.equal, it would be more explicit to have a dedicated optional-item-properties test (similar to how filterName/filterValue/searchTerm get their own optional-parameters test) to confirm the snake_case transformation of sponsored listing fields is correct independently.

@esezen esezen merged commit 8631d8b into master Jun 11, 2026
13 checks passed
@esezen esezen deleted the REM-3439/results-impression-tracking branch June 11, 2026 14:33
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