[REM-3439] Viewable impressions tracking#456
Conversation
esezen
left a comment
There was a problem hiding this comment.
Looking good, I left two small comments
There was a problem hiding this comment.
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
trackResultsImpressionViewtosrc/modules/tracker.jsto POST/v2/behavioral_action/impression_view. - Added
trackResultsImpressionViewtypings tosrc/types/tracker.d.ts. - Added a comprehensive test suite for
trackResultsImpressionViewinspec/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.
| 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(); | ||
| }); |
| 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(); | ||
| }); |
981c20f to
4282415
Compare
4282415 to
b3b3532
Compare
…nd add stricter types to tracker.d.ts
There was a problem hiding this comment.
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:
|
|
||
| trackResultsImpressionView( | ||
| parameters: { | ||
| items: (Required<Pick<ItemTracked, 'itemId' | 'itemName'>> & Omit<ItemTracked, 'itemId' | 'itemName' | 'price'>)[]; |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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.
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
trackResultsImpressionViewto thetracker.jstracker.d.tsReferences