From f26a82500174fc165a839708ff40ad7f5d3d6b2c Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Tue, 2 Dec 2025 22:36:23 -0800 Subject: [PATCH 1/5] add support for documentReferrer , canonical url --- src/modules/tracker.js | 10 ++++++++++ src/utils/helpers.js | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/modules/tracker.js b/src/modules/tracker.js index 376b4385..e9e72eb4 100644 --- a/src/modules/tracker.js +++ b/src/modules/tracker.js @@ -21,6 +21,8 @@ function applyParams(parameters, options) { beaconMode, } = options; const { host, pathname, search } = helpers.getWindowLocation(); + const canonicalUrl = helpers.getCanonicalUrl(); + const documentReferrer = helpers.getDocumentReferrer(); const sendReferrerWithTrackingEvents = (options.sendReferrerWithTrackingEvents === false) ? false : true; // Defaults to 'true' @@ -50,6 +52,14 @@ function applyParams(parameters, options) { aggregateParams.key = apiKey; } + if (documentReferrer) { + aggregateParams.document_referrer = documentReferrer; + } + + if (canonicalUrl) { + aggregateParams.canonical_url = canonicalUrl; + } + if (testCells) { Object.keys(testCells).forEach((testCellKey) => { aggregateParams[`ef-${testCellKey}`] = testCells[testCellKey]; diff --git a/src/utils/helpers.js b/src/utils/helpers.js index 6c138c51..02a2d3b1 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -91,6 +91,29 @@ const utils = { return {}; }, + getDocumentReferrer: () => { + if (utils.canUseDOM()) { + return document?.referrer; + } + + return null; + }, + + getCanonicalUrl: () => { + if (utils.canUseDOM()) { + const linkEle = document?.querySelector("link[rel='canonical']"); + let canonicalURL = null; + + if (linkEle) { + canonicalURL = linkEle.getAttribute("href"); + } + + return canonicalURL; + } + + return null; + }, + dispatchEvent: (event) => { if (utils.canUseDOM()) { window.dispatchEvent(event); From ec0d630774127a62e69b58a3d70c3e72298f58da Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Tue, 2 Dec 2025 22:36:31 -0800 Subject: [PATCH 2/5] add test boilerplate --- spec/src/modules/tracker.js | 3 ++- spec/src/utils/jsdom-global.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index 518f3743..8c9d17ce 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -26,6 +26,7 @@ const timeoutRejectionMessage = 'AbortError: This operation was aborted'; const testAnalyticsTag = { param1: 'test', param2: 'test2' }; const utmParameters = 'utm_source=attentive&utm_medium=sms&utm_campaign=campaign_1'; const url = `http://localhost.test/path/name?query=term&category=cat&${utmParameters}`; +const referrer = 'https://www.google.com/'; function validateOriginReferrer(requestParams) { expect(requestParams).to.have.property('origin_referrer').to.contain('localhost.test/path/name'); @@ -42,7 +43,7 @@ function createLongUrl(length) { describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { let fetchSpy = null; let cleanup; - const jsdomOptions = { url }; + const jsdomOptions = { url, referrer }; const requestQueueOptions = { sendTrackingEvents: true, trackingSendDelay: 1, diff --git a/spec/src/utils/jsdom-global.js b/spec/src/utils/jsdom-global.js index cca0db2f..10e9f08f 100644 --- a/spec/src/utils/jsdom-global.js +++ b/spec/src/utils/jsdom-global.js @@ -14,7 +14,7 @@ if (bundled) { cioScriptTag = ``; } -const defaultHtml = `${cioScriptTag}`; +const defaultHtml = `${cioScriptTag}`; // define this here so that we only ever dynamically populate KEYS once. const KEYS = []; From c61a0c631effcb0a77865eb300aee538d52e20ee Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Tue, 2 Dec 2025 23:13:35 -0800 Subject: [PATCH 3/5] add test --- spec/src/modules/tracker.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index 8c9d17ce..202e9b21 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -189,6 +189,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackSessionStart()).to.equal(true); + }); + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is not defined', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, From ddbd8e11076c7dd53d43636b27f7e8fc2d1b4ef5 Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Tue, 2 Dec 2025 23:14:04 -0800 Subject: [PATCH 4/5] lint --- src/utils/helpers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/helpers.js b/src/utils/helpers.js index 02a2d3b1..f779fcfc 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -101,11 +101,11 @@ const utils = { getCanonicalUrl: () => { if (utils.canUseDOM()) { - const linkEle = document?.querySelector("link[rel='canonical']"); + const linkEle = document?.querySelector('link[rel="canonical"]'); let canonicalURL = null; if (linkEle) { - canonicalURL = linkEle.getAttribute("href"); + canonicalURL = linkEle.getAttribute('href'); } return canonicalURL; From e6d5ea0a0f7b2ac4093f49daa09feba198996f5c Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Wed, 10 Dec 2025 16:17:00 -0800 Subject: [PATCH 5/5] add tests --- spec/src/modules/tracker.js | 976 +++++++++++++++++++++++++++++++++++- 1 file changed, 961 insertions(+), 15 deletions(-) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index 202e9b21..6fcd6f22 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -478,6 +478,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocusV2(userInput, parameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackInputFocus()).to.equal(true); + }); + it('Should respond with a valid response', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -1029,6 +1054,32 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { .to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); + }); + it('Should throw an error when invalid term is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); @@ -1376,6 +1427,32 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackItemDetailLoad(Object.assign(requiredParameters, optionalParameters))) + .to.equal(true); + }); + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -1761,6 +1838,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackSearchSubmit(term, Object.assign(requiredParameters, optionalParameters))).to.equal(true); + }); + it('Should respond with a valid response when term, required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -2200,6 +2302,38 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const segments = ['foo', 'bar']; + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + segments, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Body + expect(bodyParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(bodyParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -2885,6 +3019,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and userId are provided', (done) => { const userId = 'user-id'; const { tracker } = new ConstructorIO({ @@ -3408,6 +3567,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, clonedParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -3971,6 +4155,36 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestQueryParams = helpers.extractUrlParamsFromFetch(fetchSpy); + const requestBodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestQueryParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestQueryParams).to.have.property('document_referrer').to.equal(referrer); + + // Body + expect(requestBodyParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestBodyParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); + + done(); + }); + + expect(tracker.trackPurchase(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + }); + it('Should respond with a valid response when optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4436,6 +4650,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const clonedParameters = cloneDeep(requiredParameters); + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); + + done(); + }); + + delete clonedParameters.section; + + expect(tracker.trackRecommendationView(clonedParameters)).to.equal(true); + }); + it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ @@ -5119,11 +5361,9 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationClick(clonedParameters)).to.equal(true); }); - it('Should respond with a valid response when parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, - segments, fetch: fetchSpy, ...requestQueueOptions, }); @@ -5133,7 +5373,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response expect(responseParams).to.have.property('method').to.equal('POST'); @@ -5145,11 +5386,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it('Should respond with a valid response when parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, - userId, + segments, fetch: fetchSpy, ...requestQueueOptions, }); @@ -5159,7 +5400,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response expect(responseParams).to.have.property('method').to.equal('POST'); @@ -5171,8 +5412,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + userId, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('ui').to.equal(userId); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); + + done(); + }); + + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); + }); + + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5641,6 +5908,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultsLoaded(clonedParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); + + done(); + }); + + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -6035,6 +6327,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(clonedParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); + + done(); + }); + + expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -6425,6 +6742,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(clonedParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); + + done(); + }); + + expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -6850,6 +7192,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackGenericResultClick(clonedParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); + + done(); + }); + + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -7279,6 +7646,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, result_count: 0 })).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -7754,6 +8146,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when required parameters and userId are provided', (done) => { const userId = 'user-id'; const { tracker } = new ConstructorIO({ @@ -8167,6 +8584,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -8631,6 +9073,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -8921,6 +9388,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -9214,11 +9706,9 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, - segments, fetch: fetchSpy, ...requestQueueOptions, }); @@ -9228,8 +9718,35 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); - + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); + }); + + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + segments, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('us').to.deep.equal(segments); + // Response expect(responseParams).to.have.property('method').to.equal('POST'); expect(responseParams).to.have.property('message').to.equal('ok'); @@ -9515,6 +10032,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -9834,6 +10376,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); + + done(); + }); + + expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -10128,6 +10695,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -10418,6 +11010,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -10708,6 +11325,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -11001,6 +11643,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -11302,6 +11969,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -11621,6 +12313,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); + + done(); + }); + + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -11915,6 +12632,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -12227,6 +12969,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -12531,6 +13298,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -12826,6 +13618,33 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const segments = ['foo', 'bar']; + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + segments, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -13121,6 +13940,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -13417,6 +14261,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -13713,6 +14582,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -14011,6 +14905,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -14309,6 +15228,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); + it('Should send along document_referrer and canonical_url query param', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); + }); + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ @@ -14593,6 +15537,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(requestParams).to.have.property('s'); expect(requestParams).to.have.property('c').to.equal(clientVersion); expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost'); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); expect(requestParams) .to.have.property('banner_ad_id') .to.equal(requiredParameters.bannerAdId);