Skip to content

Commit c960be1

Browse files
committed
added sl in recs view tracking
1 parent 2f50c97 commit c960be1

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

spec/src/modules/tracker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4335,6 +4335,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
43354335
resultId: 'result-id',
43364336
section: 'Products',
43374337
analyticsTags: testAnalyticsTag,
4338+
slCampaignId: '019927c2-f955-4020',
4339+
slCampaignOwner: 'constructor',
43384340
};
43394341

43404342
it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => {
@@ -4563,6 +4565,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
45634565
expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId);
45644566
expect(requestParams).to.have.property('section').to.equal(optionalParameters.section);
45654567
expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag);
4568+
expect(requestParams).to.have.property('sl_campaign_id').to.deep.equal(optionalParameters.slCampaignId);
4569+
expect(requestParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner);
45664570

45674571
// Response
45684572
expect(responseParams).to.have.property('method').to.equal('POST');

src/modules/tracker.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,8 @@ class Tracker {
12321232
* @param {string[]|string|number} [parameters.seedItemIds] - Item ID(s) to be used as seed
12331233
* @param {object} [networkParameters] - Parameters relevant to the network request
12341234
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
1235+
* @param {string} [parameters.slCampaignId] - Pass campaign id of sponsored listing
1236+
* @param {string} [parameters.slCampaignOwner] - Pass campaign owner of sponsored listing
12351237
* @returns {(true|Error)}
12361238
* @description User viewed a set of recommendations
12371239
* @example
@@ -1244,6 +1246,8 @@ class Tracker {
12441246
* url: 'https://demo.constructor.io/sandbox/farmstand',
12451247
* podId: '019927c2-f955-4020',
12461248
* numResultsViewed: 3,
1249+
* slCampaignId: '019927c2-f955-4020',
1250+
* slCampaignOwner: 'constructor',
12471251
* },
12481252
* );
12491253
*/
@@ -1268,6 +1272,8 @@ class Tracker {
12681272
analyticsTags,
12691273
seedItemIds,
12701274
resultCount = result_count || items?.length || 0,
1275+
slCampaignId,
1276+
slCampaignOwner,
12711277
} = parameters;
12721278

12731279
if (!helpers.isNil(resultCount)) {
@@ -1316,6 +1322,14 @@ class Tracker {
13161322
bodyParams.seed_item_ids = seedItemIds;
13171323
}
13181324

1325+
if (slCampaignId) {
1326+
bodyParams.sl_campaign_id = slCampaignId;
1327+
}
1328+
1329+
if (slCampaignOwner) {
1330+
bodyParams.sl_campaign_owner = slCampaignOwner;
1331+
}
1332+
13191333
const requestURL = `${requestPath}${applyParamsAsString({}, this.options)}`;
13201334
const requestMethod = 'POST';
13211335
const requestBody = applyParams(bodyParams, { ...this.options, requestMethod });

src/types/tracker.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ declare class Tracker {
145145
resultId?: string;
146146
section?: string;
147147
analyticsTags?: Record<string, string>;
148+
slCampaignId?: string;
149+
slCampaignOwner?: string;
148150
},
149151
networkParameters?: NetworkParameters
150152
): true | Error;

0 commit comments

Comments
 (0)