Skip to content

Commit fc4a782

Browse files
authored
[CI-4306] Add support for slCampaignId & slCampaignOwner to autocomplete select events (#372)
* Update tests * Add slCampaign* to trackAutocompleteSelect
1 parent 706d308 commit fc4a782

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

spec/src/modules/tracker.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
696696
groupId: 'all',
697697
displayName: 'display-name',
698698
itemId: '12345',
699+
slCampaignOwner: 'Campaign Man',
700+
slCampaignId: 'Campaign 123',
699701
};
700702
const v2Parameters = {
701703
variationId: '12345-A',
@@ -730,6 +732,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
730732
expect(bodyParams).to.have.property('section').to.deep.equal(requiredParameters.section);
731733
expect(bodyParams).to.have.property('item_name').to.equal(term);
732734
expect(bodyParams).to.have.property('group_id').to.equal(optionalParameters.groupId);
735+
expect(bodyParams).to.have.property('sl_campaign_id').to.equal(optionalParameters.slCampaignId);
736+
expect(bodyParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner);
733737

734738
// Response
735739
expect(responseParams).to.have.property('method').to.equal('POST');
@@ -971,6 +975,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
971975
group_id: optionalParameters.groupId,
972976
display_name: optionalParameters.displayName,
973977
});
978+
expect(requestParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner);
979+
expect(requestParams).to.have.property('sl_campaign_id').to.deep.equal(optionalParameters.slCampaignId);
974980

975981
// Response
976982
expect(responseParams).to.have.property('method').to.equal('GET');

src/modules/tracker.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ class Tracker {
280280
* @param {string} [parameters.itemId] - Item id of the selected item
281281
* @param {string} [parameters.variationId] - Variation id of the selected item
282282
* @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"
283+
* @param {string} [parameters.slCampaignId] - Pass campaign id of sponsored listing
284+
* @param {string} [parameters.slCampaignOwner] - Pass campaign owner of sponsored listing
283285
* @param {object} [networkParameters] - Parameters relevant to the network request
284286
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
285287
* @returns {(true|Error)}
@@ -294,6 +296,8 @@ class Tracker {
294296
* groupId: '88JU230',
295297
* itemId: '12345',
296298
* variationId: '12345-A',
299+
* slCampaignId: 'Campaign 123',
300+
* slCampaignOwner: 'Store 123',
297301
* },
298302
* );
299303
*/
@@ -317,6 +321,8 @@ class Tracker {
317321
itemId = item_id,
318322
variation_id,
319323
variationId = variation_id,
324+
slCampaignId,
325+
slCampaignOwner,
320326
} = parameters;
321327
const queryParams = {};
322328
const bodyParams = {
@@ -333,6 +339,14 @@ class Tracker {
333339
queryParams.section = section;
334340
}
335341

342+
if (slCampaignId) {
343+
bodyParams.sl_campaign_id = slCampaignId;
344+
}
345+
346+
if (slCampaignOwner) {
347+
bodyParams.sl_campaign_owner = slCampaignOwner;
348+
}
349+
336350
const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`;
337351
const requestMethod = 'POST';
338352
const requestBody = applyParams(bodyParams, {
@@ -372,6 +386,8 @@ class Tracker {
372386
* @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"
373387
* @param {string} [parameters.displayName] - Display name of group of selected item
374388
* @param {string} [parameters.itemId] - Item id of the selected item
389+
* @param {string} [parameters.slCampaignId] - Pass campaign id of sponsored listing
390+
* @param {string} [parameters.slCampaignOwner] - Pass campaign owner of sponsored listing
375391
* @param {object} [networkParameters] - Parameters relevant to the network request
376392
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
377393
* @returns {(true|Error)}
@@ -386,6 +402,8 @@ class Tracker {
386402
* groupId: '88JU230',
387403
* displayName: 'apparel',
388404
* itemId: '12345',
405+
* slCampaignId: 'Campaign 123',
406+
* slCampaignOwner: 'Store 123',
389407
* },
390408
* );
391409
*/
@@ -409,6 +427,8 @@ class Tracker {
409427
displayName = display_name,
410428
item_id,
411429
itemId = item_id,
430+
slCampaignOwner,
431+
slCampaignId,
412432
} = parameters;
413433

414434
if (originalQuery) {
@@ -434,6 +454,14 @@ class Tracker {
434454
queryParams.item_id = itemId;
435455
}
436456

457+
if (slCampaignId) {
458+
queryParams.sl_campaign_id = slCampaignId;
459+
}
460+
461+
if (slCampaignOwner) {
462+
queryParams.sl_campaign_owner = slCampaignOwner;
463+
}
464+
437465
this.requests.queue(`${url}${applyParamsAsString(queryParams, this.options)}`, undefined, undefined, networkParameters);
438466
this.requests.send();
439467

@@ -737,8 +765,8 @@ class Tracker {
737765
* @param {object} [parameters.selectedFilters] - Key - Value map of selected filters
738766
* @param {string} [parameters.section] - The section name for the item Ex. "Products"
739767
* @param {object} [parameters.analyticsTags] - Pass additional analytics data
740-
* @param {object} [parameters.slCampaignId] - Pass campaign id of sponsored listing
741-
* @param {object} [parameters.slCampaignOwner] - Pass campaign owner of sponsored listing
768+
* @param {string} [parameters.slCampaignId] - Pass campaign id of sponsored listing
769+
* @param {string} [parameters.slCampaignOwner] - Pass campaign owner of sponsored listing
742770
* @param {object} [networkParameters] - Parameters relevant to the network request
743771
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
744772
* @returns {(true|Error)}
@@ -849,8 +877,8 @@ class Tracker {
849877
* @param {string} [parameters.itemIsConvertible] - Whether or not an item is available for a conversion
850878
* @param {string} [parameters.section] - The section name for the item Ex. "Products"
851879
* @param {object} [parameters.analyticsTags] - Pass additional analytics data
852-
* @param {object} [parameters.slCampaignId] - Pass campaign id of sponsored listing
853-
* @param {object} [parameters.slCampaignOwner] - Pass campaign owner of sponsored listing
880+
* @param {string} [parameters.slCampaignId] - Pass campaign id of sponsored listing
881+
* @param {string} [parameters.slCampaignOwner] - Pass campaign owner of sponsored listing
854882
* @param {object} [networkParameters] - Parameters relevant to the network request
855883
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
856884
* @returns {(true|Error)}
@@ -1557,8 +1585,8 @@ class Tracker {
15571585
* @param {number} [parameters.numResultsPerPage] - Number of results shown
15581586
* @param {object} [parameters.selectedFilters] - Selected filters
15591587
* @param {object} [parameters.analyticsTags] - Pass additional analytics data
1560-
* @param {object} [parameters.slCampaignId] - Pass campaign id of sponsored listing
1561-
* @param {object} [parameters.slCampaignOwner] - Pass campaign owner of sponsored listing
1588+
* @param {string} [parameters.slCampaignId] - Pass campaign id of sponsored listing
1589+
* @param {string} [parameters.slCampaignOwner] - Pass campaign owner of sponsored listing
15621590
* @param {object} [networkParameters] - Parameters relevant to the network request
15631591
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
15641592
* @returns {(true|Error)}

src/types/tracker.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ declare class Tracker {
4545
groupId?: string;
4646
displayName?: string;
4747
itemId?: string;
48+
slCampaignId?: string;
49+
slCampaignOwner?: string;
4850
},
4951
networkParameters?: NetworkParameters
5052
): true | Error;

0 commit comments

Comments
 (0)