Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions spec/src/modules/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,10 +694,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
tr: 'click',
groupId: 'All',
displayName: 'display-name',
itemId: '12345',
};
const v2Parameters = {
variationId: '12345-A',
itemId: '12345',
};

it('V2 Should respond with a valid response when term and required parameters are provided', (done) => {
Expand All @@ -724,7 +724,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
// Body
expect(bodyParams).to.have.property('user_input').to.equal(requiredParameters.originalQuery);
expect(bodyParams).to.have.property('tr').to.equal(optionalParameters.tr);
expect(bodyParams).to.have.property('item_id').to.equal(v2Parameters.itemId);
expect(bodyParams).to.have.property('item_id').to.equal(optionalParameters.itemId);
expect(bodyParams).to.have.property('variation_id').to.equal(v2Parameters.variationId);
expect(bodyParams).to.have.property('section').to.deep.equal(requiredParameters.section);
expect(bodyParams).to.have.property('item_name').to.equal(term);
Expand Down Expand Up @@ -811,6 +811,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
tr: 'click',
group_id: 'all',
display_name: 'display-name',
item_id: '12345',
};

tracker.on('success', (responseParams) => {
Expand All @@ -825,6 +826,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
expect(requestParams).to.have.property('_dt');
expect(requestParams).to.have.property('origin_referrer').to.equal('localhost.test/path/name');
expect(requestParams).to.have.property('original_query').to.equal(snakeCaseParameters.original_query);
expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id);
expect(requestParams).to.have.property('section').to.equal(snakeCaseParameters.section);
expect(requestParams).to.have.property('group').to.deep.equal({
display_name: snakeCaseParameters.display_name,
Expand Down Expand Up @@ -963,6 +965,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('tr').to.equal(optionalParameters.tr);
expect(requestParams).to.have.property('item_id').to.equal(optionalParameters.itemId);
expect(requestParams).to.have.property('group').to.deep.equal({
group_id: optionalParameters.groupId,
display_name: optionalParameters.displayName,
Expand Down
8 changes: 8 additions & 0 deletions src/modules/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class Tracker {
* @param {string} [parameters.tr] - Trigger used to select the item (click, etc.)
* @param {string} [parameters.groupId] - Group identifier of the group to search within. Only required if searching within a group, i.e. "Pumpkin in Canned Goods"
* @param {string} [parameters.displayName] - Display name of group of selected item
* @param {string} [parameters.itemId] - Item id of the selected item
* @param {object} [networkParameters] - Parameters relevant to the network request
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
* @returns {(true|Error)}
Expand All @@ -383,6 +384,7 @@ class Tracker {
* tr: 'click',
* groupId: '88JU230',
* displayName: 'apparel',
* itemId: '12345',
* },
* );
*/
Expand All @@ -404,6 +406,8 @@ class Tracker {
groupId = group_id,
display_name,
displayName = display_name,
item_id,
itemId = item_id,
} = parameters;

if (originalQuery) {
Expand All @@ -425,6 +429,10 @@ class Tracker {
};
}

if (itemId) {
queryParams.item_id = itemId;
}

this.requests.queue(`${url}${applyParamsAsString(queryParams, this.options)}`, undefined, undefined, networkParameters);
this.requests.send();

Expand Down
5 changes: 3 additions & 2 deletions src/types/tracker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ declare class Tracker {
userInput: string;
analyticsTags?: Record<string, string>;
},
networkParameters?: NetworkParameters,
networkParameters?: NetworkParameters
): true | Error;

trackItemDetailLoad(
Expand All @@ -44,6 +44,7 @@ declare class Tracker {
tr?: string;
groupId?: string;
displayName?: string;
itemId?: string;
},
networkParameters?: NetworkParameters
): true | Error;
Expand Down Expand Up @@ -312,7 +313,7 @@ declare class Tracker {

trackAssistantSearchSubmit(
parameters: {
intent: string,
intent: string;
searchTerm: string;
userInput: string;
searchResultId: string;
Expand Down
Loading