From c902fea7ba35be6beb49d9b4460a5a66195bf646 Mon Sep 17 00:00:00 2001 From: Chris Gee Date: Tue, 17 Jun 2025 08:58:43 -0700 Subject: [PATCH 01/12] Add asa pdp methods --- src/modules/tracker.js | 586 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 586 insertions(+) diff --git a/src/modules/tracker.js b/src/modules/tracker.js index 2a2b9922..6cc63d78 100644 --- a/src/modules/tracker.js +++ b/src/modules/tracker.js @@ -2774,6 +2774,592 @@ class Tracker { return new Error('parameters is a required parameter of type object'); } + /** + * Send Assistant PDP view events + * + * @function trackAssistantPDPViews + * @param {object} parameters - Additional parameters to be sent with request + * @param {array} parameters.questions - List of pre-defined questions shown to the user + * @param {string} parameters.itemId - Product id whose page we are on + * @param {string} parameters.itemName - Product name whose page we are one + * @param {array.<{start: string | undefined, + * end: string | undefined}>} parameters.viewTimespans - List of timestamp pairs in ISO_8601 format + * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.section] - The section name for the item Ex. "Products" + * @param {object} [networkParameters] - Parameters relevant to the network request + * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) + * @returns {(true|Error)} + * @description The PDP Q&A element appeared in the visible part of the page + * @example + * constructorio.tracker.trackAssistantPDPViews({ + * { + * 'itemId': '1', + * 'itemName': 'item1', + * 'variationId': '2', + * 'questions': [ + * 'Why choose this?', + * 'How is this product made?', + * 'What are the dimensions of this product?' + * ], + * 'viewTimespans': [ + * { + * 'start': '2025-05-19T14:30:00+02:00', + * 'end': '2025-05-19T14:30:05+02:00' + * }, + * { + * 'start': '2025-05-19T14:30:10+02:00', + * 'end': '2025-05-19T14:30:15+02:00' + * } + * ] + * }, + * ); + */ + trackAssistantPDPViews(parameters, networkParameters = {}) { + // Ensure parameters are provided (required) + if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { + // Ensure parameters are provided (required) + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_view?`; + const { + section, + questions, + itemId, + itemName, + variationId, + viewTimespans, + } = parameters; + const queryParams = {}; + const bodyParams = { + questions, + itemId, + itemName, + variationId, + section, + viewTimespans, + }; + + if (section) { + queryParams.section = originalSection || section; + } + + const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; + const requestMethod = 'POST'; + const requestBody = applyParams(bodyParams, { + ...this.options, + requestMethod, + }); + this.requests.queue( + requestURL, + requestMethod, + requestBody, + networkParameters, + ); + this.requests.send(); + return true; + } + + this.requests.send(); + + return new Error('parameters is a required parameter of type object'); + } + + /** + * Send Assistant PDP view event + * + * @function trackAssistantPDPView + * @param {object} parameters - Additional parameters to be sent with request + * @param {array} parameters.questions - List of pre-defined questions shown to the user + * @param {string} parameters.itemId - Product id whose page we are on + * @param {string} parameters.itemName - Product name whose page we are one + * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.section] - The section name for the item Ex. "Products" + * @param {object} [networkParameters] - Parameters relevant to the network request + * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) + * @returns {(true|Error)} + * @description The PDP Q&A element appeared in the visible part of the page + * @example + * constructorio.tracker.trackAssistantPDPView({ + * { + * 'itemId': '1', + * 'itemName': 'item1', + * 'variationId': '2', + * 'questions': [ + * 'Why choose this?', + * 'How is this product made?', + * 'What are the dimensions of this product?' + * ], + * }, + * ); + */ + trackAssistantPDPView(parameters, networkParameters = {}) { + // Ensure parameters are provided (required) + if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { + // Ensure parameters are provided (required) + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_view?`; + const { + section, + questions, + itemId, + itemName, + variationId, + } = parameters; + const queryParams = {}; + const bodyParams = { + questions, + itemId, + itemName, + variationId, + section, + }; + + if (section) { + queryParams.section = originalSection || section; + } + + const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; + const requestMethod = 'POST'; + const requestBody = applyParams(bodyParams, { + ...this.options, + requestMethod, + }); + this.requests.queue( + requestURL, + requestMethod, + requestBody, + networkParameters, + ); + this.requests.send(); + return true; + } + + this.requests.send(); + + return new Error('parameters is a required parameter of type object'); + } + + /** + * Send Assistant PDP out of view event + * + * @function trackAssistantPDPOutOfView + * @param {object} parameters - Additional parameters to be sent with request + * @param {string} parameters.itemId - Product id whose page we are on + * @param {string} parameters.itemName - Product name whose page we are one + * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.section] - The section name for the item Ex. "Products" + * @param {object} [networkParameters] - Parameters relevant to the network request + * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) + * @returns {(true|Error)} + * @description The PDP Q&A element disappeared from the visible part of the page + * @example + * constructorio.tracker.trackAssistantPDPOutOfView({ + * { + * 'itemId': '1', + * 'itemName': 'item1', + * 'variationId': '2', + * }, + * ); + */ + trackAssistantPDPOutOfView(parameters, networkParameters = {}) { + // Ensure parameters are provided (required) + if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { + // Ensure parameters are provided (required) + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_out_of_view?`; + const { + section, + itemId, + itemName, + variationId, + } = parameters; + const queryParams = {}; + const bodyParams = { + itemId, + itemName, + variationId, + section, + }; + + if (section) { + queryParams.section = originalSection || section; + } + + const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; + const requestMethod = 'POST'; + const requestBody = applyParams(bodyParams, { + ...this.options, + requestMethod, + }); + this.requests.queue( + requestURL, + requestMethod, + requestBody, + networkParameters, + ); + this.requests.send(); + return true; + } + + this.requests.send(); + + return new Error('parameters is a required parameter of type object'); + } + + /** + * Send Assistant PDP out of view event + * + * @function trackAssistantPDPFocus + * @param {object} parameters - Additional parameters to be sent with request + * @param {string} parameters.itemId - Product id whose page we are on + * @param {string} parameters.itemName - Product name whose page we are one + * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.section] - The section name for the item Ex. "Products" + * @param {object} [networkParameters] - Parameters relevant to the network request + * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) + * @returns {(true|Error)} + * @description The PDP Q&A element was focused on + * @example + * constructorio.tracker.trackAssistantPDPFocus({ + * { + * 'itemId': '1', + * 'itemName': 'item1', + * 'variationId': '2', + * }, + * ); + */ + trackAssistantPDPFocus(parameters, networkParameters = {}) { + // Ensure parameters are provided (required) + if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { + // Ensure parameters are provided (required) + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_focus?`; + const { + section, + itemId, + itemName, + variationId, + } = parameters; + const queryParams = {}; + const bodyParams = { + itemId, + itemName, + variationId, + section, + }; + + if (section) { + queryParams.section = originalSection || section; + } + + const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; + const requestMethod = 'POST'; + const requestBody = applyParams(bodyParams, { + ...this.options, + requestMethod, + }); + this.requests.queue( + requestURL, + requestMethod, + requestBody, + networkParameters, + ); + this.requests.send(); + return true; + } + + this.requests.send(); + + return new Error('parameters is a required parameter of type object'); + } + + /** + * Send Assistant PDP question click event + * + * @function trackAssistantQuestionClick + * @param {object} parameters - Additional parameters to be sent with request + * @param {string} parameters.itemId - Product id whose page we are on + * @param {string} parameters.itemName - Product name whose page we are one + * @param {string} parameters.question - Question a user clicked on + * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.section] - The section name for the item Ex. "Products" + * @param {object} [networkParameters] - Parameters relevant to the network request + * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) + * @returns {(true|Error)} + * @description The PDP Q&A question that was clicked on + * @example + * constructorio.tracker.trackAssistantQuestionClick({ + * { + * 'itemId': '1', + * 'itemName': 'item1', + * 'variationId': '2', + * 'question': 'Why choose this?' + * }, + * ); + */ + trackAssistantQuestionClick(parameters, networkParameters = {}) { + // Ensure parameters are provided (required) + if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { + // Ensure parameters are provided (required) + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_focus?`; + const { + section, + itemId, + itemName, + variationId, + question, + } = parameters; + const queryParams = {}; + const bodyParams = { + itemId, + itemName, + variationId, + section, + question, + }; + + if (section) { + queryParams.section = originalSection || section; + } + + const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; + const requestMethod = 'POST'; + const requestBody = applyParams(bodyParams, { + ...this.options, + requestMethod, + }); + this.requests.queue( + requestURL, + requestMethod, + requestBody, + networkParameters, + ); + this.requests.send(); + return true; + } + + this.requests.send(); + + return new Error('parameters is a required parameter of type object'); + } + + /** + * Send Assistant PDP question submit + * + * @function trackAssistantQuestionSubmit + * @param {object} parameters - Additional parameters to be sent with request + * @param {string} parameters.itemId - Product id whose page we are on + * @param {string} parameters.itemName - Product name whose page we are one + * @param {string} parameters.question - Question a user submitted + * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.section] - The section name for the item Ex. "Products" + * @param {object} [networkParameters] - Parameters relevant to the network request + * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) + * @returns {(true|Error)} + * @description The PDP Q&A question was submitted + * @example + * constructorio.tracker.trackAssistantQuestionSubmit({ + * { + * 'itemId': '1', + * 'itemName': 'item1', + * 'variationId': '2', + * 'question': 'Tell me some key highlights about this item?' + * }, + * ); + */ + trackAssistantQuestionSubmit(parameters, networkParameters = {}) { + // Ensure parameters are provided (required) + if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { + // Ensure parameters are provided (required) + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_question_submit?`; + const { + section, + itemId, + itemName, + variationId, + question, + } = parameters; + const queryParams = {}; + const bodyParams = { + itemId, + itemName, + variationId, + section, + question, + }; + + if (section) { + queryParams.section = originalSection || section; + } + + const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; + const requestMethod = 'POST'; + const requestBody = applyParams(bodyParams, { + ...this.options, + requestMethod, + }); + this.requests.queue( + requestURL, + requestMethod, + requestBody, + networkParameters, + ); + this.requests.send(); + return true; + } + + this.requests.send(); + + return new Error('parameters is a required parameter of type object'); + } + + /** + * Send Assistant PDP answer view + * + * @function trackAssistantAnswerView + * @param {object} parameters - Additional parameters to be sent with request + * @param {string} parameters.itemId - Product id whose page we are on + * @param {string} parameters.itemName - Product name whose page we are one + * @param {string} parameters.question - Question a user submitted + * @param {string} parameters.answerText - Answer text of the question + * @param {string} [parameters.qnaResultId] - Answer result id returned + * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.section] - The section name for the item Ex. "Products" + * @param {object} [networkParameters] - Parameters relevant to the network request + * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) + * @returns {(true|Error)} + * @description The PDP Q&A answer was shown to the user + * @example + * constructorio.tracker.trackAssistantAnswerView({ + * { + * 'itemId': '1', + * 'itemName': 'item1', + * 'variationId': '2', + * 'question': 'Why choose this?', + * 'answerText': 'This product is awesome!', + * 'qnaResultId': '0daf0015-fc29-4727-9140-8d5313a1902c', + * }, + * ); + */ + trackAssistantAnswerView(parameters, networkParameters = {}) { + // Ensure parameters are provided (required) + if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { + // Ensure parameters are provided (required) + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_answer_view?`; + const { + section, + itemId, + itemName, + variationId, + question, + answerText, + qnaResultId, + } = parameters; + const queryParams = {}; + const bodyParams = { + itemId, + itemName, + variationId, + section, + question, + answerText, + qnaResultId, + }; + + if (section) { + queryParams.section = originalSection || section; + } + + const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; + const requestMethod = 'POST'; + const requestBody = applyParams(bodyParams, { + ...this.options, + requestMethod, + }); + this.requests.queue( + requestURL, + requestMethod, + requestBody, + networkParameters, + ); + this.requests.send(); + return true; + } + + this.requests.send(); + + return new Error('parameters is a required parameter of type object'); + } + + /** + * Send Assistant PDP answer feedback + * + * @function trackAssistantAnswerFeedback + * @param {object} parameters - Additional parameters to be sent with request + * @param {string} parameters.itemId - Product id whose page we are on + * @param {string} parameters.itemName - Product name whose page we are one + * @param {string} parameters.feedbackLabel - Feedback value: either "thumbs_up" or "thumbs_down" + * @param {string} [parameters.qnaResultId] - Answer result id returned + * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.section] - The section name for the item Ex. "Products" + * @param {object} [networkParameters] - Parameters relevant to the network request + * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) + * @returns {(true|Error)} + * @description A user provided feedback on an answers usefulness + * @example + * constructorio.tracker.trackAssistantAnswerFeedback({ + * { + * 'itemId': '1', + * 'itemName': 'item1', + * 'variationId': '2', + * 'feedbackLabel': 'thumbs_up', + * 'qnaResultId': '0daf0015-fc29-4727-9140-8d5313a1902c', + * }, + * ); + */ + trackAssistantAnswerFeedback(parameters, networkParameters = {}) { + // Ensure parameters are provided (required) + if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { + // Ensure parameters are provided (required) + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_answer_feedback?`; + const { + section, + itemId, + itemName, + variationId, + feedbackLabel, + qnaResultId, + } = parameters; + const queryParams = {}; + const bodyParams = { + itemId, + itemName, + variationId, + section, + feedbackLabel, + qnaResultId, + }; + + if (section) { + queryParams.section = originalSection || section; + } + + const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; + const requestMethod = 'POST'; + const requestBody = applyParams(bodyParams, { + ...this.options, + requestMethod, + }); + this.requests.queue( + requestURL, + requestMethod, + requestBody, + networkParameters, + ); + this.requests.send(); + return true; + } + + this.requests.send(); + + return new Error('parameters is a required parameter of type object'); + } + /** * Subscribe to success or error messages emitted by tracking requests * From 4910e201f970ba86dc47ef9702b1093d7d90cf59 Mon Sep 17 00:00:00 2001 From: Chris Gee Date: Tue, 17 Jun 2025 14:39:53 -0700 Subject: [PATCH 02/12] Add types --- src/types/index.d.ts | 5 ++++ src/types/tracker.d.ts | 68 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/types/index.d.ts b/src/types/index.d.ts index bb2d74ca..ef76f8ee 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -246,3 +246,8 @@ export interface ItemTracked { export interface ItemTrackedPurchase extends ItemTracked { count?: number; } + +export interface TimeSpan { + start: string; + end: string; +} diff --git a/src/types/tracker.d.ts b/src/types/tracker.d.ts index d8846715..52055742 100644 --- a/src/types/tracker.d.ts +++ b/src/types/tracker.d.ts @@ -1,5 +1,5 @@ import EventEmitter = require('events'); -import { ConstructorClientOptions, ItemTracked, ItemTrackedPurchase, NetworkParameters } from '.'; +import { ConstructorClientOptions, ItemTracked, ItemTrackedPurchase, TimeSpan, NetworkParameters } from '.'; import RequestQueue = require('../utils/request-queue'); export default Tracker; @@ -331,5 +331,71 @@ declare class Tracker { networkParameters?: NetworkParameters ): true | Error; + trackAssistantPDPViews(parameters: { + questions: string[]; + itemId: string; + itemName: string; + viewTimespans: TimeSpan[]; + variationId?: string; + section?: string; + }, networkParameters?: NetworkParameters): true | Error; + + trackAssistantPDPView(parameters: { + questions: string[]; + itemId: string; + itemName: string; + variationId?: string; + section?: string; + }, networkParameters?: NetworkParameters): true | Error; + + trackAssistantPDPOutOfView(parameters: { + itemId: string; + itemName: string; + variationId?: string; + section?: string; + }, networkParameters?: NetworkParameters): true | Error; + + trackAssistantPDPFocus(parameters: { + itemId: string; + itemName: string; + variationId?: string; + section?: string; + }, networkParameters?: NetworkParameters): true | Error; + + trackAssistantQuestionClick(parameters: { + itemId: string; + itemName: string; + question: string; + variationId?: string; + section?: string; + }, networkParameters?: NetworkParameters): true | Error; + + trackAssistantQuestionSubmit(parameters: { + itemId: string; + itemName: string; + question: string; + variationId?: string; + section?: string; + }, networkParameters?: NetworkParameters): true | Error; + + trackAssistantAnswerView(parameters: { + itemId: string; + itemName: string; + question: string; + answerText: string; + qnaResultId?: string; + variationId?: string; + section?: string; + }, networkParameters?: NetworkParameters): true | Error; + + trackAssistantAnswerFeedback(parameters: { + itemId: string; + itemName: string; + feedbackLabel: string; + qnaResultId?: string; + variationId?: string; + section?: string; + }, networkParameters?: NetworkParameters): true | Error; + on(messageType: string, callback: Function): true | Error; } From 9480764418b399eb26c0e3016b9880cdd1e72be7 Mon Sep 17 00:00:00 2001 From: Chris Gee Date: Tue, 17 Jun 2025 16:14:48 -0700 Subject: [PATCH 03/12] Add tests --- spec/src/modules/tracker.js | 1766 +++++++++++++++++++++++++++++++++++ src/modules/tracker.js | 108 +-- src/types/tracker.d.ts | 8 +- 3 files changed, 1820 insertions(+), 62 deletions(-) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index 955bee1e..b44455a1 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -10089,4 +10089,1770 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); }); }); + + describe.only('trackAssistantPDPOutOfView', () => { + const requiredParameters = { itemId: '1', itemName: 'item1', }; + const optionalParameters = { + section: 'Products', + variationId: '2', + }; + + it('Should respond with a valid response when term and required parameters 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('key'); + expect(requestParams).to.have.property('i'); + 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('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPOutOfView(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'); + + done(); + }); + + expect(tracker.trackAssistantPDPOutOfView(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({ + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPOutOfView(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, + testCells, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + }); + + it('Should respond with a valid response when required and optional parameters are provided', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPOutOfView(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + }); + + it('Should throw an error when no parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPDPOutOfView()).to.be.an('error'); + }); + + it('Should throw an error when invalid parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPDPOutOfView()).to.be.an('error'); + }); + + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: true, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + }); + + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: false, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).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(); + }); + + expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + }); + + if (!skipNetworkTimeoutTests) { + it('Should be rejected when network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPDPOutOfView(requiredParameters, { timeout: 10 })).to.equal(true); + }); + + it('Should be rejected when global network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + networkParameters: { + timeout: 20, + }, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + }); + } + + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; + const userId = `user-id ${specialCharacters}`; + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + }); + + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; + const userId = `user-id ${breakingSpaces} user-id`; + const userIdExpected = 'user-id 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(userIdExpected); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + }); + }); + + describe.only('trackAssistantPDPFocus', () => { + const requiredParameters = { itemId: '1', itemName: 'item1', }; + const optionalParameters = { + section: 'Products', + variationId: '2', + }; + + it('Should respond with a valid response when term and required parameters 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('key'); + expect(requestParams).to.have.property('i'); + 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('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPFocus(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'); + + done(); + }); + + expect(tracker.trackAssistantPDPFocus(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({ + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPFocus(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, + testCells, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + }); + + it('Should respond with a valid response when required and optional parameters are provided', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPFocus(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + }); + + it('Should throw an error when no parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPDPFocus()).to.be.an('error'); + }); + + it('Should throw an error when invalid parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPDPFocus()).to.be.an('error'); + }); + + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: true, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + }); + + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: false, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).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(); + }); + + expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + }); + + if (!skipNetworkTimeoutTests) { + it('Should be rejected when network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPDPFocus(requiredParameters, { timeout: 10 })).to.equal(true); + }); + + it('Should be rejected when global network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + networkParameters: { + timeout: 20, + }, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + }); + } + + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; + const userId = `user-id ${specialCharacters}`; + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + }); + + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; + const userId = `user-id ${breakingSpaces} user-id`; + const userIdExpected = 'user-id 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(userIdExpected); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + }); + }); + + describe.only('trackAssistantPDPQuestionClick', () => { + const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', }; + const optionalParameters = { + section: 'Products', + variationId: '2', + }; + + it('Should respond with a valid response when term and required parameters 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('key'); + expect(requestParams).to.have.property('i'); + 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('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('question').to.equal(requiredParameters.question); + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionClick(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'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionClick(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({ + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionClick(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, + testCells, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + }); + + it('Should respond with a valid response when required and optional parameters are provided', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionClick(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + }); + + it('Should throw an error when no parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPDPQuestionClick()).to.be.an('error'); + }); + + it('Should throw an error when invalid parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPDPQuestionClick()).to.be.an('error'); + }); + + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: true, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + }); + + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: false, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).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(); + }); + + expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + }); + + if (!skipNetworkTimeoutTests) { + it('Should be rejected when network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPDPQuestionClick(requiredParameters, { timeout: 10 })).to.equal(true); + }); + + it('Should be rejected when global network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + networkParameters: { + timeout: 20, + }, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + }); + } + + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; + const userId = `user-id ${specialCharacters}`; + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + }); + + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; + const userId = `user-id ${breakingSpaces} user-id`; + const userIdExpected = 'user-id 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(userIdExpected); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + }); + }); + + describe.only('trackAssistantPDPQuestionSubmit', () => { + const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', }; + const optionalParameters = { + section: 'Products', + variationId: '2', + }; + + it('Should respond with a valid response when term and required parameters 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('key'); + expect(requestParams).to.have.property('i'); + 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('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('question').to.equal(requiredParameters.question); + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionSubmit(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'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionSubmit(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({ + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionSubmit(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, + testCells, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + }); + + it('Should respond with a valid response when required and optional parameters are provided', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionSubmit(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + }); + + it('Should throw an error when no parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPDPQuestionSubmit()).to.be.an('error'); + }); + + it('Should throw an error when invalid parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPDPQuestionSubmit()).to.be.an('error'); + }); + + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: true, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + }); + + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: false, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).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(); + }); + + expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + }); + + if (!skipNetworkTimeoutTests) { + it('Should be rejected when network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters, { timeout: 10 })).to.equal(true); + }); + + it('Should be rejected when global network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + networkParameters: { + timeout: 20, + }, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + }); + } + + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; + const userId = `user-id ${specialCharacters}`; + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + }); + + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; + const userId = `user-id ${breakingSpaces} user-id`; + const userIdExpected = 'user-id 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(userIdExpected); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + }); + }); + + describe.only('trackAssistantPDPAnswerView', () => { + const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', answerText: 'This product is awesome!', }; + const optionalParameters = { + section: 'Products', + variationId: '2', + qnaResultId: '0daf0015-fc29-4727-9140-8d5313a1902c', + }; + + it('Should respond with a valid response when term and required parameters 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('key'); + expect(requestParams).to.have.property('i'); + 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('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('question').to.equal(requiredParameters.question); + expect(requestParams).to.have.property('answer_text').to.equal(requiredParameters.answerText); + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerView(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'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerView(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({ + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerView(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, + testCells, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + }); + + it('Should respond with a valid response when required and optional parameters are provided', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(bodyParams).to.have.property('qna_result_id').to.equal(optionalParameters.qnaResultId); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerView(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + }); + + it('Should throw an error when no parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPDPAnswerView()).to.be.an('error'); + }); + + it('Should throw an error when invalid parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPDPAnswerView()).to.be.an('error'); + }); + + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: true, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + }); + + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: false, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).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(); + }); + + expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + }); + + if (!skipNetworkTimeoutTests) { + it('Should be rejected when network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPDPAnswerView(requiredParameters, { timeout: 10 })).to.equal(true); + }); + + it('Should be rejected when global network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + networkParameters: { + timeout: 20, + }, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + }); + } + + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; + const userId = `user-id ${specialCharacters}`; + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + }); + + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; + const userId = `user-id ${breakingSpaces} user-id`; + const userIdExpected = 'user-id 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(userIdExpected); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + }); + }); + + describe.only('trackAssistantPDPAnswerFeedback', () => { + const requiredParameters = { itemId: '1', itemName: 'item1', feedbackLabel: 'thumbs_up', }; + const optionalParameters = { + section: 'Products', + variationId: '2', + qnaResultId: '0daf0015-fc29-4727-9140-8d5313a1902c', + }; + + it('Should respond with a valid response when term and required parameters 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('key'); + expect(requestParams).to.have.property('i'); + 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('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('feedback_label').to.equal(requiredParameters.feedbackLabel); + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerFeedback(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'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerFeedback(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({ + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerFeedback(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, + testCells, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + }); + + it('Should respond with a valid response when required and optional parameters are provided', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('qna_result_id').to.equal(optionalParameters.qnaResultId); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerFeedback(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + }); + + it('Should throw an error when no parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPDPAnswerFeedback()).to.be.an('error'); + }); + + it('Should throw an error when invalid parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPDPAnswerFeedback()).to.be.an('error'); + }); + + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: true, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + }); + + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: false, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).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(); + }); + + expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + }); + + if (!skipNetworkTimeoutTests) { + it('Should be rejected when network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters, { timeout: 10 })).to.equal(true); + }); + + it('Should be rejected when global network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + networkParameters: { + timeout: 20, + }, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + }); + } + + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; + const userId = `user-id ${specialCharacters}`; + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + }); + + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; + const userId = `user-id ${breakingSpaces} user-id`; + const userIdExpected = 'user-id 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(userIdExpected); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + }); + }); }); diff --git a/src/modules/tracker.js b/src/modules/tracker.js index 6cc63d78..de0f0455 100644 --- a/src/modules/tracker.js +++ b/src/modules/tracker.js @@ -2830,15 +2830,14 @@ class Tracker { const queryParams = {}; const bodyParams = { questions, - itemId, - itemName, - variationId, - section, - viewTimespans, + item_id: itemId, + item_name: itemName, + variation_id: variationId, + view_timespans: viewTimespans, }; if (section) { - queryParams.section = originalSection || section; + queryParams.section = section; } const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; @@ -2905,14 +2904,13 @@ class Tracker { const queryParams = {}; const bodyParams = { questions, - itemId, - itemName, - variationId, - section, + item_id: itemId, + item_name: itemName, + variation_id: variationId, }; if (section) { - queryParams.section = originalSection || section; + queryParams.section = section; } const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; @@ -2971,14 +2969,13 @@ class Tracker { } = parameters; const queryParams = {}; const bodyParams = { - itemId, - itemName, - variationId, - section, + item_id: itemId, + item_name: itemName, + variation_id: variationId, }; if (section) { - queryParams.section = originalSection || section; + queryParams.section = section; } const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; @@ -3037,14 +3034,13 @@ class Tracker { } = parameters; const queryParams = {}; const bodyParams = { - itemId, - itemName, - variationId, - section, + item_id: itemId, + item_name: itemName, + variation_id: variationId, }; if (section) { - queryParams.section = originalSection || section; + queryParams.section = section; } const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; @@ -3071,7 +3067,7 @@ class Tracker { /** * Send Assistant PDP question click event * - * @function trackAssistantQuestionClick + * @function trackAssistantPDPQuestionClick * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are one @@ -3083,7 +3079,7 @@ class Tracker { * @returns {(true|Error)} * @description The PDP Q&A question that was clicked on * @example - * constructorio.tracker.trackAssistantQuestionClick({ + * constructorio.tracker.trackAssistantPDPQuestionClick({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3092,11 +3088,11 @@ class Tracker { * }, * ); */ - trackAssistantQuestionClick(parameters, networkParameters = {}) { + trackAssistantPDPQuestionClick(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { // Ensure parameters are provided (required) - const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_focus?`; + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_question_click?`; const { section, itemId, @@ -3106,15 +3102,14 @@ class Tracker { } = parameters; const queryParams = {}; const bodyParams = { - itemId, - itemName, - variationId, - section, + item_id: itemId, + item_name: itemName, + variation_id: variationId, question, }; if (section) { - queryParams.section = originalSection || section; + queryParams.section = section; } const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; @@ -3141,7 +3136,7 @@ class Tracker { /** * Send Assistant PDP question submit * - * @function trackAssistantQuestionSubmit + * @function trackAssistantPDPQuestionSubmit * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are one @@ -3153,7 +3148,7 @@ class Tracker { * @returns {(true|Error)} * @description The PDP Q&A question was submitted * @example - * constructorio.tracker.trackAssistantQuestionSubmit({ + * constructorio.tracker.trackAssistantPDPQuestionSubmit({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3162,7 +3157,7 @@ class Tracker { * }, * ); */ - trackAssistantQuestionSubmit(parameters, networkParameters = {}) { + trackAssistantPDPQuestionSubmit(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { // Ensure parameters are provided (required) @@ -3176,15 +3171,14 @@ class Tracker { } = parameters; const queryParams = {}; const bodyParams = { - itemId, - itemName, - variationId, - section, + item_id: itemId, + item_name: itemName, + variation_id: variationId, question, }; if (section) { - queryParams.section = originalSection || section; + queryParams.section = section; } const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; @@ -3211,7 +3205,7 @@ class Tracker { /** * Send Assistant PDP answer view * - * @function trackAssistantAnswerView + * @function trackAssistantPDPAnswerView * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are one @@ -3225,7 +3219,7 @@ class Tracker { * @returns {(true|Error)} * @description The PDP Q&A answer was shown to the user * @example - * constructorio.tracker.trackAssistantAnswerView({ + * constructorio.tracker.trackAssistantPDPAnswerView({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3236,7 +3230,7 @@ class Tracker { * }, * ); */ - trackAssistantAnswerView(parameters, networkParameters = {}) { + trackAssistantPDPAnswerView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { // Ensure parameters are provided (required) @@ -3252,17 +3246,16 @@ class Tracker { } = parameters; const queryParams = {}; const bodyParams = { - itemId, - itemName, - variationId, - section, + item_id: itemId, + item_name: itemName, + variation_id: variationId, question, - answerText, - qnaResultId, + answer_text: answerText, + qna_result_id: qnaResultId, }; if (section) { - queryParams.section = originalSection || section; + queryParams.section = section; } const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; @@ -3289,7 +3282,7 @@ class Tracker { /** * Send Assistant PDP answer feedback * - * @function trackAssistantAnswerFeedback + * @function trackAssistantPDPAnswerFeedback * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are one @@ -3302,7 +3295,7 @@ class Tracker { * @returns {(true|Error)} * @description A user provided feedback on an answers usefulness * @example - * constructorio.tracker.trackAssistantAnswerFeedback({ + * constructorio.tracker.trackAssistantPDPAnswerFeedback({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3312,7 +3305,7 @@ class Tracker { * }, * ); */ - trackAssistantAnswerFeedback(parameters, networkParameters = {}) { + trackAssistantPDPAnswerFeedback(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { // Ensure parameters are provided (required) @@ -3327,16 +3320,15 @@ class Tracker { } = parameters; const queryParams = {}; const bodyParams = { - itemId, - itemName, - variationId, - section, - feedbackLabel, - qnaResultId, + item_id: itemId, + item_name: itemName, + variation_id: variationId, + feedback_label: feedbackLabel, + qna_result_id: qnaResultId, }; if (section) { - queryParams.section = originalSection || section; + queryParams.section = section; } const requestURL = `${baseUrl}${applyParamsAsString(queryParams, this.options)}`; diff --git a/src/types/tracker.d.ts b/src/types/tracker.d.ts index 52055742..bc7854c0 100644 --- a/src/types/tracker.d.ts +++ b/src/types/tracker.d.ts @@ -362,7 +362,7 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantQuestionClick(parameters: { + trackAssistantPDPQuestionClick(parameters: { itemId: string; itemName: string; question: string; @@ -370,7 +370,7 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantQuestionSubmit(parameters: { + trackAssistantPDPQuestionSubmit(parameters: { itemId: string; itemName: string; question: string; @@ -378,7 +378,7 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantAnswerView(parameters: { + trackAssistantPDPAnswerView(parameters: { itemId: string; itemName: string; question: string; @@ -388,7 +388,7 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantAnswerFeedback(parameters: { + trackAssistantPDPAnswerFeedback(parameters: { itemId: string; itemName: string; feedbackLabel: string; From 82276cef454deac226637a0a2ff78b0c8f764bd2 Mon Sep 17 00:00:00 2001 From: Chris Gee Date: Tue, 17 Jun 2025 16:28:09 -0700 Subject: [PATCH 04/12] lint --- cspell.json | 3 ++- spec/src/modules/tracker.js | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cspell.json b/cspell.json index 65f1a318..1a988a7b 100644 --- a/cspell.json +++ b/cspell.json @@ -47,6 +47,7 @@ "rerank", "atcs", "testdata", - "Bytespider" + "Bytespider", + "Timespans" ] } diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index b44455a1..0ccdfdcb 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -10091,7 +10091,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); describe.only('trackAssistantPDPOutOfView', () => { - const requiredParameters = { itemId: '1', itemName: 'item1', }; + const requiredParameters = { itemId: '1', itemName: 'item1' }; const optionalParameters = { section: 'Products', variationId: '2', @@ -10384,7 +10384,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); describe.only('trackAssistantPDPFocus', () => { - const requiredParameters = { itemId: '1', itemName: 'item1', }; + const requiredParameters = { itemId: '1', itemName: 'item1' }; const optionalParameters = { section: 'Products', variationId: '2', @@ -10677,7 +10677,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); describe.only('trackAssistantPDPQuestionClick', () => { - const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', }; + const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?' }; const optionalParameters = { section: 'Products', variationId: '2', @@ -10816,7 +10816,9 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionClick(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + expect(tracker.trackAssistantPDPQuestionClick( + Object.assign(requiredParameters, optionalParameters), + )).to.equal(true); }); it('Should throw an error when no parameters are provided', () => { @@ -10971,7 +10973,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); describe.only('trackAssistantPDPQuestionSubmit', () => { - const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', }; + const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?' }; const optionalParameters = { section: 'Products', variationId: '2', @@ -11110,7 +11112,9 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionSubmit(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + expect(tracker.trackAssistantPDPQuestionSubmit( + Object.assign(requiredParameters, optionalParameters), + )).to.equal(true); }); it('Should throw an error when no parameters are provided', () => { @@ -11265,7 +11269,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); describe.only('trackAssistantPDPAnswerView', () => { - const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', answerText: 'This product is awesome!', }; + const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', answerText: 'This product is awesome!' }; const optionalParameters = { section: 'Products', variationId: '2', @@ -11562,7 +11566,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); describe.only('trackAssistantPDPAnswerFeedback', () => { - const requiredParameters = { itemId: '1', itemName: 'item1', feedbackLabel: 'thumbs_up', }; + const requiredParameters = { itemId: '1', itemName: 'item1', feedbackLabel: 'thumbs_up' }; const optionalParameters = { section: 'Products', variationId: '2', @@ -11702,7 +11706,9 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerFeedback(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + expect(tracker.trackAssistantPDPAnswerFeedback( + Object.assign(requiredParameters, optionalParameters), + )).to.equal(true); }); it('Should throw an error when no parameters are provided', () => { From 244170fc7902f15576dc312084e02785b85bed46 Mon Sep 17 00:00:00 2001 From: Chris Gee Date: Wed, 18 Jun 2025 08:01:20 -0700 Subject: [PATCH 05/12] Remove onlys --- spec/src/modules/tracker.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index 0ccdfdcb..b7e4f40e 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -10090,7 +10090,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe.only('trackAssistantPDPOutOfView', () => { + describe('trackAssistantPDPOutOfView', () => { const requiredParameters = { itemId: '1', itemName: 'item1' }; const optionalParameters = { section: 'Products', @@ -10383,7 +10383,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe.only('trackAssistantPDPFocus', () => { + describe('trackAssistantPDPFocus', () => { const requiredParameters = { itemId: '1', itemName: 'item1' }; const optionalParameters = { section: 'Products', @@ -10676,7 +10676,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe.only('trackAssistantPDPQuestionClick', () => { + describe('trackAssistantPDPQuestionClick', () => { const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?' }; const optionalParameters = { section: 'Products', @@ -10972,7 +10972,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe.only('trackAssistantPDPQuestionSubmit', () => { + describe('trackAssistantPDPQuestionSubmit', () => { const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?' }; const optionalParameters = { section: 'Products', @@ -11268,7 +11268,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe.only('trackAssistantPDPAnswerView', () => { + describe('trackAssistantPDPAnswerView', () => { const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', answerText: 'This product is awesome!' }; const optionalParameters = { section: 'Products', @@ -11565,7 +11565,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe.only('trackAssistantPDPAnswerFeedback', () => { + describe('trackAssistantPDPAnswerFeedback', () => { const requiredParameters = { itemId: '1', itemName: 'item1', feedbackLabel: 'thumbs_up' }; const optionalParameters = { section: 'Products', From 3141637216a1c6949468ae38154eb83d16bd8f29 Mon Sep 17 00:00:00 2001 From: Chris Gee Date: Tue, 24 Jun 2025 02:47:01 -0700 Subject: [PATCH 06/12] Correct casing --- spec/src/modules/tracker.js | 168 ++++++++++++++++++------------------ src/modules/tracker.js | 48 +++++------ src/types/tracker.d.ts | 16 ++-- 3 files changed, 116 insertions(+), 116 deletions(-) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index b7e4f40e..88823a3d 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -10090,7 +10090,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('trackAssistantPDPOutOfView', () => { + describe('trackAssistantPdpOutOfView', () => { const requiredParameters = { itemId: '1', itemName: 'item1' }; const optionalParameters = { section: 'Products', @@ -10125,7 +10125,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -10151,7 +10151,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -10177,7 +10177,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -10203,7 +10203,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -10229,19 +10229,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPOutOfView(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + expect(tracker.trackAssistantPdpOutOfView(Object.assign(requiredParameters, optionalParameters))).to.equal(true); }); it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPDPOutOfView()).to.be.an('error'); + expect(tracker.trackAssistantPdpOutOfView()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPDPOutOfView()).to.be.an('error'); + expect(tracker.trackAssistantPdpOutOfView()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -10266,7 +10266,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -10291,7 +10291,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -10306,7 +10306,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPOutOfView(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackAssistantPdpOutOfView(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -10323,7 +10323,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); }); } @@ -10351,7 +10351,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -10379,11 +10379,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); }); }); - describe('trackAssistantPDPFocus', () => { + describe('trackAssistantPdpFocus', () => { const requiredParameters = { itemId: '1', itemName: 'item1' }; const optionalParameters = { section: 'Products', @@ -10418,7 +10418,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -10444,7 +10444,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -10470,7 +10470,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -10496,7 +10496,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -10522,19 +10522,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPFocus(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + expect(tracker.trackAssistantPdpFocus(Object.assign(requiredParameters, optionalParameters))).to.equal(true); }); it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPDPFocus()).to.be.an('error'); + expect(tracker.trackAssistantPdpFocus()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPDPFocus()).to.be.an('error'); + expect(tracker.trackAssistantPdpFocus()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -10559,7 +10559,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -10584,7 +10584,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -10599,7 +10599,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPFocus(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackAssistantPdpFocus(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -10616,7 +10616,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); }); } @@ -10644,7 +10644,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -10672,11 +10672,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPFocus(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); }); }); - describe('trackAssistantPDPQuestionClick', () => { + describe('trackAssistantPdpQuestionClick', () => { const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?' }; const optionalParameters = { section: 'Products', @@ -10712,7 +10712,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -10738,7 +10738,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -10764,7 +10764,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -10790,7 +10790,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -10816,7 +10816,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionClick( + expect(tracker.trackAssistantPdpQuestionClick( Object.assign(requiredParameters, optionalParameters), )).to.equal(true); }); @@ -10824,13 +10824,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPDPQuestionClick()).to.be.an('error'); + expect(tracker.trackAssistantPdpQuestionClick()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPDPQuestionClick()).to.be.an('error'); + expect(tracker.trackAssistantPdpQuestionClick()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -10855,7 +10855,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -10880,7 +10880,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -10895,7 +10895,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionClick(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackAssistantPdpQuestionClick(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -10912,7 +10912,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); }); } @@ -10940,7 +10940,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -10968,11 +10968,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); }); }); - describe('trackAssistantPDPQuestionSubmit', () => { + describe('trackAssistantPdpQuestionSubmit', () => { const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?' }; const optionalParameters = { section: 'Products', @@ -11008,7 +11008,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -11034,7 +11034,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -11060,7 +11060,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -11086,7 +11086,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -11112,7 +11112,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionSubmit( + expect(tracker.trackAssistantPdpQuestionSubmit( Object.assign(requiredParameters, optionalParameters), )).to.equal(true); }); @@ -11120,13 +11120,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPDPQuestionSubmit()).to.be.an('error'); + expect(tracker.trackAssistantPdpQuestionSubmit()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPDPQuestionSubmit()).to.be.an('error'); + expect(tracker.trackAssistantPdpQuestionSubmit()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -11151,7 +11151,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -11176,7 +11176,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -11191,7 +11191,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -11208,7 +11208,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); }); } @@ -11236,7 +11236,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -11264,11 +11264,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); }); }); - describe('trackAssistantPDPAnswerView', () => { + describe('trackAssistantPdpAnswerView', () => { const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', answerText: 'This product is awesome!' }; const optionalParameters = { section: 'Products', @@ -11306,7 +11306,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -11332,7 +11332,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -11358,7 +11358,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -11384,7 +11384,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -11411,19 +11411,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerView(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + expect(tracker.trackAssistantPdpAnswerView(Object.assign(requiredParameters, optionalParameters))).to.equal(true); }); it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPDPAnswerView()).to.be.an('error'); + expect(tracker.trackAssistantPdpAnswerView()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPDPAnswerView()).to.be.an('error'); + expect(tracker.trackAssistantPdpAnswerView()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -11448,7 +11448,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -11473,7 +11473,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -11488,7 +11488,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerView(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackAssistantPdpAnswerView(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -11505,7 +11505,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); }); } @@ -11533,7 +11533,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -11561,11 +11561,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); }); }); - describe('trackAssistantPDPAnswerFeedback', () => { + describe('trackAssistantPdpAnswerFeedback', () => { const requiredParameters = { itemId: '1', itemName: 'item1', feedbackLabel: 'thumbs_up' }; const optionalParameters = { section: 'Products', @@ -11602,7 +11602,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -11628,7 +11628,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -11654,7 +11654,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -11680,7 +11680,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -11706,7 +11706,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerFeedback( + expect(tracker.trackAssistantPdpAnswerFeedback( Object.assign(requiredParameters, optionalParameters), )).to.equal(true); }); @@ -11714,13 +11714,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPDPAnswerFeedback()).to.be.an('error'); + expect(tracker.trackAssistantPdpAnswerFeedback()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPDPAnswerFeedback()).to.be.an('error'); + expect(tracker.trackAssistantPdpAnswerFeedback()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -11745,7 +11745,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -11770,7 +11770,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -11785,7 +11785,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -11802,7 +11802,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); }); } @@ -11830,7 +11830,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -11858,7 +11858,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPDPAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); }); }); }); diff --git a/src/modules/tracker.js b/src/modules/tracker.js index de0f0455..2610445b 100644 --- a/src/modules/tracker.js +++ b/src/modules/tracker.js @@ -2777,7 +2777,7 @@ class Tracker { /** * Send Assistant PDP view events * - * @function trackAssistantPDPViews + * @function trackAssistantPdpViews * @param {object} parameters - Additional parameters to be sent with request * @param {array} parameters.questions - List of pre-defined questions shown to the user * @param {string} parameters.itemId - Product id whose page we are on @@ -2791,7 +2791,7 @@ class Tracker { * @returns {(true|Error)} * @description The PDP Q&A element appeared in the visible part of the page * @example - * constructorio.tracker.trackAssistantPDPViews({ + * constructorio.tracker.trackAssistantPdpViews({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -2814,7 +2814,7 @@ class Tracker { * }, * ); */ - trackAssistantPDPViews(parameters, networkParameters = {}) { + trackAssistantPdpViews(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { // Ensure parameters are provided (required) @@ -2864,7 +2864,7 @@ class Tracker { /** * Send Assistant PDP view event * - * @function trackAssistantPDPView + * @function trackAssistantPdpView * @param {object} parameters - Additional parameters to be sent with request * @param {array} parameters.questions - List of pre-defined questions shown to the user * @param {string} parameters.itemId - Product id whose page we are on @@ -2876,7 +2876,7 @@ class Tracker { * @returns {(true|Error)} * @description The PDP Q&A element appeared in the visible part of the page * @example - * constructorio.tracker.trackAssistantPDPView({ + * constructorio.tracker.trackAssistantPdpView({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -2889,7 +2889,7 @@ class Tracker { * }, * ); */ - trackAssistantPDPView(parameters, networkParameters = {}) { + trackAssistantPdpView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { // Ensure parameters are provided (required) @@ -2937,7 +2937,7 @@ class Tracker { /** * Send Assistant PDP out of view event * - * @function trackAssistantPDPOutOfView + * @function trackAssistantPdpOutOfView * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are one @@ -2948,7 +2948,7 @@ class Tracker { * @returns {(true|Error)} * @description The PDP Q&A element disappeared from the visible part of the page * @example - * constructorio.tracker.trackAssistantPDPOutOfView({ + * constructorio.tracker.trackAssistantPdpOutOfView({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -2956,7 +2956,7 @@ class Tracker { * }, * ); */ - trackAssistantPDPOutOfView(parameters, networkParameters = {}) { + trackAssistantPdpOutOfView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { // Ensure parameters are provided (required) @@ -3002,7 +3002,7 @@ class Tracker { /** * Send Assistant PDP out of view event * - * @function trackAssistantPDPFocus + * @function trackAssistantPdpFocus * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are one @@ -3013,7 +3013,7 @@ class Tracker { * @returns {(true|Error)} * @description The PDP Q&A element was focused on * @example - * constructorio.tracker.trackAssistantPDPFocus({ + * constructorio.tracker.trackAssistantPdpFocus({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3021,7 +3021,7 @@ class Tracker { * }, * ); */ - trackAssistantPDPFocus(parameters, networkParameters = {}) { + trackAssistantPdpFocus(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { // Ensure parameters are provided (required) @@ -3067,7 +3067,7 @@ class Tracker { /** * Send Assistant PDP question click event * - * @function trackAssistantPDPQuestionClick + * @function trackAssistantPdpQuestionClick * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are one @@ -3079,7 +3079,7 @@ class Tracker { * @returns {(true|Error)} * @description The PDP Q&A question that was clicked on * @example - * constructorio.tracker.trackAssistantPDPQuestionClick({ + * constructorio.tracker.trackAssistantPdpQuestionClick({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3088,7 +3088,7 @@ class Tracker { * }, * ); */ - trackAssistantPDPQuestionClick(parameters, networkParameters = {}) { + trackAssistantPdpQuestionClick(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { // Ensure parameters are provided (required) @@ -3136,7 +3136,7 @@ class Tracker { /** * Send Assistant PDP question submit * - * @function trackAssistantPDPQuestionSubmit + * @function trackAssistantPdpQuestionSubmit * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are one @@ -3148,7 +3148,7 @@ class Tracker { * @returns {(true|Error)} * @description The PDP Q&A question was submitted * @example - * constructorio.tracker.trackAssistantPDPQuestionSubmit({ + * constructorio.tracker.trackAssistantPdpQuestionSubmit({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3157,7 +3157,7 @@ class Tracker { * }, * ); */ - trackAssistantPDPQuestionSubmit(parameters, networkParameters = {}) { + trackAssistantPdpQuestionSubmit(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { // Ensure parameters are provided (required) @@ -3205,7 +3205,7 @@ class Tracker { /** * Send Assistant PDP answer view * - * @function trackAssistantPDPAnswerView + * @function trackAssistantPdpAnswerView * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are one @@ -3219,7 +3219,7 @@ class Tracker { * @returns {(true|Error)} * @description The PDP Q&A answer was shown to the user * @example - * constructorio.tracker.trackAssistantPDPAnswerView({ + * constructorio.tracker.trackAssistantPdpAnswerView({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3230,7 +3230,7 @@ class Tracker { * }, * ); */ - trackAssistantPDPAnswerView(parameters, networkParameters = {}) { + trackAssistantPdpAnswerView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { // Ensure parameters are provided (required) @@ -3282,7 +3282,7 @@ class Tracker { /** * Send Assistant PDP answer feedback * - * @function trackAssistantPDPAnswerFeedback + * @function trackAssistantPdpAnswerFeedback * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are one @@ -3295,7 +3295,7 @@ class Tracker { * @returns {(true|Error)} * @description A user provided feedback on an answers usefulness * @example - * constructorio.tracker.trackAssistantPDPAnswerFeedback({ + * constructorio.tracker.trackAssistantPdpAnswerFeedback({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3305,7 +3305,7 @@ class Tracker { * }, * ); */ - trackAssistantPDPAnswerFeedback(parameters, networkParameters = {}) { + trackAssistantPdpAnswerFeedback(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { // Ensure parameters are provided (required) diff --git a/src/types/tracker.d.ts b/src/types/tracker.d.ts index bc7854c0..8a5b3a99 100644 --- a/src/types/tracker.d.ts +++ b/src/types/tracker.d.ts @@ -331,7 +331,7 @@ declare class Tracker { networkParameters?: NetworkParameters ): true | Error; - trackAssistantPDPViews(parameters: { + trackAssistantPdpViews(parameters: { questions: string[]; itemId: string; itemName: string; @@ -340,7 +340,7 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPDPView(parameters: { + trackAssistantPdpView(parameters: { questions: string[]; itemId: string; itemName: string; @@ -348,21 +348,21 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPDPOutOfView(parameters: { + trackAssistantPdpOutOfView(parameters: { itemId: string; itemName: string; variationId?: string; section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPDPFocus(parameters: { + trackAssistantPdpFocus(parameters: { itemId: string; itemName: string; variationId?: string; section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPDPQuestionClick(parameters: { + trackAssistantPdpQuestionClick(parameters: { itemId: string; itemName: string; question: string; @@ -370,7 +370,7 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPDPQuestionSubmit(parameters: { + trackAssistantPdpQuestionSubmit(parameters: { itemId: string; itemName: string; question: string; @@ -378,7 +378,7 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPDPAnswerView(parameters: { + trackAssistantPdpAnswerView(parameters: { itemId: string; itemName: string; question: string; @@ -388,7 +388,7 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPDPAnswerFeedback(parameters: { + trackAssistantPdpAnswerFeedback(parameters: { itemId: string; itemName: string; feedbackLabel: string; From cacce270fecd3c024d20ac819688c0354acb1f7c Mon Sep 17 00:00:00 2001 From: Chris Gee Date: Thu, 26 Jun 2025 11:49:34 -0700 Subject: [PATCH 07/12] Update questions --- spec/src/modules/tracker.js | 615 ++++++++++++++++++++++++++++++++++++ src/modules/tracker.js | 26 +- src/types/index.d.ts | 4 + src/types/tracker.d.ts | 6 +- 4 files changed, 631 insertions(+), 20 deletions(-) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index 88823a3d..e6cd16c6 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -10090,6 +10090,621 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); + describe('trackAssistantPdpViews', () => { + const requiredParameters = { + itemId: '1', + itemName: 'item1', + questions: [ + { question: 'Why choose this?' }, + { question: 'How is this product made?' }, + { question: 'What are the dimensions of this product?' }, + ], + viewTimespans: [ + { + 'start': '2025-05-19T14:30:00+02:00', + 'end': '2025-05-19T14:30:05+02:00' + }, + { + 'start': '2025-05-19T14:30:10+02:00', + 'end': '2025-05-19T14:30:15+02:00' + } + ] + }; + const optionalParameters = { + section: 'Products', + variationId: '2', + }; + + it('Should respond with a valid response when term and required parameters 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('key'); + expect(requestParams).to.have.property('i'); + 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('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('questions').to.deep.equal(requiredParameters.questions); + expect(requestParams).to.have.property('view_timespans').to.deep.equal(requiredParameters.viewTimespans); + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpViews(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'); + + done(); + }); + + expect(tracker.trackAssistantPdpViews(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({ + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpViews(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, + testCells, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + }); + + it('Should respond with a valid response when required and optional parameters are provided', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpViews(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + }); + + it('Should throw an error when no parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPdpViews()).to.be.an('error'); + }); + + it('Should throw an error when invalid parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPdpViews()).to.be.an('error'); + }); + + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: true, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + }); + + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: false, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).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(); + }); + + expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + }); + + if (!skipNetworkTimeoutTests) { + it('Should be rejected when network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPdpViews(requiredParameters, { timeout: 10 })).to.equal(true); + }); + + it('Should be rejected when global network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + networkParameters: { + timeout: 20, + }, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + }); + } + + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; + const userId = `user-id ${specialCharacters}`; + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + }); + + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; + const userId = `user-id ${breakingSpaces} user-id`; + const userIdExpected = 'user-id 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(userIdExpected); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + }); + }); + + describe('trackAssistantPdpView', () => { + const requiredParameters = { + itemId: '1', + itemName: 'item1', + questions: [ + { question: 'Why choose this?' }, + { question: 'How is this product made?' }, + { question: 'What are the dimensions of this product?' }, + ], + }; + const optionalParameters = { + section: 'Products', + variationId: '2', + }; + + it('Should respond with a valid response when term and required parameters 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('key'); + expect(requestParams).to.have.property('i'); + 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('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('questions').to.deep.equal(requiredParameters.questions); + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpView(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'); + + done(); + }); + + expect(tracker.trackAssistantPdpView(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({ + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpView(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, + testCells, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + }); + + it('Should respond with a valid response when required and optional parameters are provided', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); + const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpView(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + }); + + it('Should throw an error when no parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPdpView()).to.be.an('error'); + }); + + it('Should throw an error when invalid parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKey }); + + expect(tracker.trackAssistantPdpView()).to.be.an('error'); + }); + + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: true, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + validateOriginReferrer(requestParams); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + }); + + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + fetch: fetchSpy, + sendReferrerWithTrackingEvents: false, + ...requestQueueOptions, + }); + + tracker.on('success', (responseParams) => { + const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); + + // Request + expect(fetchSpy).to.have.been.called; + expect(requestParams).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(); + }); + + expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + }); + + if (!skipNetworkTimeoutTests) { + it('Should be rejected when network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPdpView(requiredParameters, { timeout: 10 })).to.equal(true); + }); + + it('Should be rejected when global network request timeout is provided and reached', (done) => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKey, + networkParameters: { + timeout: 20, + }, + ...requestQueueOptions, + }); + + tracker.on('error', ({ message }) => { + expect(message).to.equal(timeoutRejectionMessage); + done(); + }); + + expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + }); + } + + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; + const userId = `user-id ${specialCharacters}`; + 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').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + }); + + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; + const userId = `user-id ${breakingSpaces} user-id`; + const userIdExpected = 'user-id 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(userIdExpected); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + }); + }); + describe('trackAssistantPdpOutOfView', () => { const requiredParameters = { itemId: '1', itemName: 'item1' }; const optionalParameters = { diff --git a/src/modules/tracker.js b/src/modules/tracker.js index 2610445b..2857c5e3 100644 --- a/src/modules/tracker.js +++ b/src/modules/tracker.js @@ -2779,7 +2779,7 @@ class Tracker { * * @function trackAssistantPdpViews * @param {object} parameters - Additional parameters to be sent with request - * @param {array} parameters.questions - List of pre-defined questions shown to the user + * @param {array.<{question: string}>} parameters.questions - List of pre-defined questions shown to the user * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are one * @param {array.<{start: string | undefined, @@ -2797,9 +2797,9 @@ class Tracker { * 'itemName': 'item1', * 'variationId': '2', * 'questions': [ - * 'Why choose this?', - * 'How is this product made?', - * 'What are the dimensions of this product?' + * { question: 'Why choose this?' }, + * { question: 'How is this product made?' }, + * { question: 'What are the dimensions of this product?' } * ], * 'viewTimespans': [ * { @@ -2817,8 +2817,7 @@ class Tracker { trackAssistantPdpViews(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - // Ensure parameters are provided (required) - const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_view?`; + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_views?`; const { section, questions, @@ -2866,7 +2865,7 @@ class Tracker { * * @function trackAssistantPdpView * @param {object} parameters - Additional parameters to be sent with request - * @param {array} parameters.questions - List of pre-defined questions shown to the user + * @param {array.<{question: string}>} parameters.questions - List of pre-defined questions shown to the user * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are one * @param {string} [parameters.variationId] - Variation id whose page we are one @@ -2882,9 +2881,9 @@ class Tracker { * 'itemName': 'item1', * 'variationId': '2', * 'questions': [ - * 'Why choose this?', - * 'How is this product made?', - * 'What are the dimensions of this product?' + * { question: 'Why choose this?' }, + * { question: 'How is this product made?' }, + * { question: 'What are the dimensions of this product?' } * ], * }, * ); @@ -2892,7 +2891,6 @@ class Tracker { trackAssistantPdpView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - // Ensure parameters are provided (required) const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_view?`; const { section, @@ -2959,7 +2957,6 @@ class Tracker { trackAssistantPdpOutOfView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - // Ensure parameters are provided (required) const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_out_of_view?`; const { section, @@ -3024,7 +3021,6 @@ class Tracker { trackAssistantPdpFocus(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - // Ensure parameters are provided (required) const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_focus?`; const { section, @@ -3091,7 +3087,6 @@ class Tracker { trackAssistantPdpQuestionClick(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - // Ensure parameters are provided (required) const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_question_click?`; const { section, @@ -3160,7 +3155,6 @@ class Tracker { trackAssistantPdpQuestionSubmit(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - // Ensure parameters are provided (required) const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_question_submit?`; const { section, @@ -3233,7 +3227,6 @@ class Tracker { trackAssistantPdpAnswerView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - // Ensure parameters are provided (required) const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_answer_view?`; const { section, @@ -3308,7 +3301,6 @@ class Tracker { trackAssistantPdpAnswerFeedback(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - // Ensure parameters are provided (required) const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_answer_feedback?`; const { section, diff --git a/src/types/index.d.ts b/src/types/index.d.ts index ef76f8ee..c0eab5ea 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -247,6 +247,10 @@ export interface ItemTrackedPurchase extends ItemTracked { count?: number; } +export interface Question { + question: string; +} + export interface TimeSpan { start: string; end: string; diff --git a/src/types/tracker.d.ts b/src/types/tracker.d.ts index 8a5b3a99..600e6706 100644 --- a/src/types/tracker.d.ts +++ b/src/types/tracker.d.ts @@ -1,5 +1,5 @@ import EventEmitter = require('events'); -import { ConstructorClientOptions, ItemTracked, ItemTrackedPurchase, TimeSpan, NetworkParameters } from '.'; +import { ConstructorClientOptions, ItemTracked, ItemTrackedPurchase, Question, TimeSpan, NetworkParameters } from '.'; import RequestQueue = require('../utils/request-queue'); export default Tracker; @@ -332,7 +332,7 @@ declare class Tracker { ): true | Error; trackAssistantPdpViews(parameters: { - questions: string[]; + questions: Question[]; itemId: string; itemName: string; viewTimespans: TimeSpan[]; @@ -341,7 +341,7 @@ declare class Tracker { }, networkParameters?: NetworkParameters): true | Error; trackAssistantPdpView(parameters: { - questions: string[]; + questions: Question[]; itemId: string; itemName: string; variationId?: string; From 1aacecd9dda6f3331a57112b280c2db8eaba1ea7 Mon Sep 17 00:00:00 2001 From: Chris Gee Date: Thu, 26 Jun 2025 11:51:35 -0700 Subject: [PATCH 08/12] lint --- spec/src/modules/tracker.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index e6cd16c6..e3fcef93 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -10095,20 +10095,20 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { itemId: '1', itemName: 'item1', questions: [ - { question: 'Why choose this?' }, - { question: 'How is this product made?' }, - { question: 'What are the dimensions of this product?' }, + { question: 'Why choose this?' }, + { question: 'How is this product made?' }, + { question: 'What are the dimensions of this product?' }, ], viewTimespans: [ { - 'start': '2025-05-19T14:30:00+02:00', - 'end': '2025-05-19T14:30:05+02:00' + start: '2025-05-19T14:30:00+02:00', + end: '2025-05-19T14:30:05+02:00', }, { - 'start': '2025-05-19T14:30:10+02:00', - 'end': '2025-05-19T14:30:15+02:00' - } - ] + start: '2025-05-19T14:30:10+02:00', + end: '2025-05-19T14:30:15+02:00', + }, + ], }; const optionalParameters = { section: 'Products', @@ -10408,9 +10408,9 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { itemId: '1', itemName: 'item1', questions: [ - { question: 'Why choose this?' }, - { question: 'How is this product made?' }, - { question: 'What are the dimensions of this product?' }, + { question: 'Why choose this?' }, + { question: 'How is this product made?' }, + { question: 'What are the dimensions of this product?' }, ], }; const optionalParameters = { From e4823cbf146891ee19a06490515d684bd084dc89 Mon Sep 17 00:00:00 2001 From: Chris Gee Date: Sun, 29 Jun 2025 22:59:57 -0700 Subject: [PATCH 09/12] Address comments --- src/modules/tracker.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/modules/tracker.js b/src/modules/tracker.js index 2857c5e3..a7eb1276 100644 --- a/src/modules/tracker.js +++ b/src/modules/tracker.js @@ -2781,10 +2781,10 @@ class Tracker { * @param {object} parameters - Additional parameters to be sent with request * @param {array.<{question: string}>} parameters.questions - List of pre-defined questions shown to the user * @param {string} parameters.itemId - Product id whose page we are on - * @param {string} parameters.itemName - Product name whose page we are one + * @param {string} parameters.itemName - Product name whose page we are on * @param {array.<{start: string | undefined, * end: string | undefined}>} parameters.viewTimespans - List of timestamp pairs in ISO_8601 format - * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.variationId] - Variation id whose page we are on * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) @@ -2867,8 +2867,8 @@ class Tracker { * @param {object} parameters - Additional parameters to be sent with request * @param {array.<{question: string}>} parameters.questions - List of pre-defined questions shown to the user * @param {string} parameters.itemId - Product id whose page we are on - * @param {string} parameters.itemName - Product name whose page we are one - * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} parameters.itemName - Product name whose page we are on + * @param {string} [parameters.variationId] - Variation id whose page we are on * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) @@ -2938,8 +2938,8 @@ class Tracker { * @function trackAssistantPdpOutOfView * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on - * @param {string} parameters.itemName - Product name whose page we are one - * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} parameters.itemName - Product name whose page we are on + * @param {string} [parameters.variationId] - Variation id whose page we are on * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) @@ -3002,13 +3002,13 @@ class Tracker { * @function trackAssistantPdpFocus * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on - * @param {string} parameters.itemName - Product name whose page we are one - * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} parameters.itemName - Product name whose page we are on + * @param {string} [parameters.variationId] - Variation id whose page we are on * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} - * @description The PDP Q&A element was focused on + * @description User focused on the PDP Q&A input element * @example * constructorio.tracker.trackAssistantPdpFocus({ * { @@ -3066,9 +3066,9 @@ class Tracker { * @function trackAssistantPdpQuestionClick * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on - * @param {string} parameters.itemName - Product name whose page we are one + * @param {string} parameters.itemName - Product name whose page we are on * @param {string} parameters.question - Question a user clicked on - * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.variationId] - Variation id whose page we are on * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) @@ -3134,9 +3134,9 @@ class Tracker { * @function trackAssistantPdpQuestionSubmit * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on - * @param {string} parameters.itemName - Product name whose page we are one + * @param {string} parameters.itemName - Product name whose page we are on * @param {string} parameters.question - Question a user submitted - * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.variationId] - Variation id whose page we are on * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) @@ -3202,11 +3202,11 @@ class Tracker { * @function trackAssistantPdpAnswerView * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on - * @param {string} parameters.itemName - Product name whose page we are one + * @param {string} parameters.itemName - Product name whose page we are on * @param {string} parameters.question - Question a user submitted * @param {string} parameters.answerText - Answer text of the question * @param {string} [parameters.qnaResultId] - Answer result id returned - * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.variationId] - Variation id whose page we are on * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) @@ -3278,10 +3278,10 @@ class Tracker { * @function trackAssistantPdpAnswerFeedback * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on - * @param {string} parameters.itemName - Product name whose page we are one + * @param {string} parameters.itemName - Product name whose page we are on * @param {string} parameters.feedbackLabel - Feedback value: either "thumbs_up" or "thumbs_down" * @param {string} [parameters.qnaResultId] - Answer result id returned - * @param {string} [parameters.variationId] - Variation id whose page we are one + * @param {string} [parameters.variationId] - Variation id whose page we are on * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) From 5d8b72eaec758114bdd0f02226e38b3c566f2eec Mon Sep 17 00:00:00 2001 From: Chris Gee Date: Tue, 1 Jul 2025 10:46:10 -0700 Subject: [PATCH 10/12] Update PIA naming --- spec/src/modules/tracker.js | 234 +++++++++++++++++++----------------- src/modules/tracker.js | 78 ++++++------ src/types/tracker.d.ts | 16 +-- 3 files changed, 169 insertions(+), 159 deletions(-) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index e3fcef93..5f14fc9b 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -10090,7 +10090,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('trackAssistantPdpViews', () => { + describe('trackProductInsightsAgentViews', () => { const requiredParameters = { itemId: '1', itemName: 'item1', @@ -10145,7 +10145,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -10171,7 +10171,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -10197,7 +10197,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -10223,7 +10223,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -10249,19 +10249,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpViews(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + expect(tracker.trackProductInsightsAgentViews( + Object.assign(requiredParameters, optionalParameters), + )).to.equal(true); }); it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpViews()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentViews()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpViews()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentViews()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -10286,7 +10288,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -10311,7 +10313,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -10326,7 +10328,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpViews(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -10343,7 +10345,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); } @@ -10371,7 +10373,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -10399,11 +10401,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpViews(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); }); - describe('trackAssistantPdpView', () => { + describe('trackProductInsightsAgentView', () => { const requiredParameters = { itemId: '1', itemName: 'item1', @@ -10447,7 +10449,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -10473,7 +10475,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -10499,7 +10501,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -10525,7 +10527,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -10551,19 +10553,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpView(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + expect(tracker.trackProductInsightsAgentView( + Object.assign(requiredParameters, optionalParameters), + )).to.equal(true); }); it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpView()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentView()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpView()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentView()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -10588,7 +10592,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -10613,7 +10617,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -10628,7 +10632,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpView(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -10645,7 +10649,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); } @@ -10673,7 +10677,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -10701,11 +10705,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); }); - describe('trackAssistantPdpOutOfView', () => { + describe('trackProductInsightsAgentOutOfView', () => { const requiredParameters = { itemId: '1', itemName: 'item1' }; const optionalParameters = { section: 'Products', @@ -10740,7 +10744,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -10766,7 +10770,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -10792,7 +10796,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -10818,7 +10822,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -10844,19 +10848,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpOutOfView(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView( + Object.assign(requiredParameters, optionalParameters), + )).to.equal(true); }); it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpOutOfView()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentOutOfView()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpOutOfView()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentOutOfView()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -10881,7 +10887,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -10906,7 +10912,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -10921,7 +10927,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpOutOfView(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -10938,7 +10944,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); } @@ -10966,7 +10972,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -10994,11 +11000,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpOutOfView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); }); - describe('trackAssistantPdpFocus', () => { + describe('trackProductInsightsAgentFocus', () => { const requiredParameters = { itemId: '1', itemName: 'item1' }; const optionalParameters = { section: 'Products', @@ -11033,7 +11039,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -11059,7 +11065,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -11085,7 +11091,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -11111,7 +11117,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -11137,19 +11143,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpFocus(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus( + Object.assign(requiredParameters, optionalParameters), + )).to.equal(true); }); it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpFocus()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentFocus()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpFocus()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentFocus()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -11174,7 +11182,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -11199,7 +11207,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -11214,7 +11222,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpFocus(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -11231,7 +11239,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); } @@ -11259,7 +11267,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -11287,11 +11295,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpFocus(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); }); - describe('trackAssistantPdpQuestionClick', () => { + describe('trackProductInsightsAgentQuestionClick', () => { const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?' }; const optionalParameters = { section: 'Products', @@ -11327,7 +11335,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -11353,7 +11361,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -11379,7 +11387,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -11405,7 +11413,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -11431,7 +11439,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionClick( + expect(tracker.trackProductInsightsAgentQuestionClick( Object.assign(requiredParameters, optionalParameters), )).to.equal(true); }); @@ -11439,13 +11447,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpQuestionClick()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentQuestionClick()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpQuestionClick()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentQuestionClick()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -11470,7 +11478,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -11495,7 +11503,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -11510,7 +11518,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionClick(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -11527,7 +11535,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); } @@ -11555,7 +11563,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -11583,11 +11591,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionClick(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); }); - describe('trackAssistantPdpQuestionSubmit', () => { + describe('trackProductInsightsAgentQuestionSubmit', () => { const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?' }; const optionalParameters = { section: 'Products', @@ -11623,7 +11631,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -11649,7 +11657,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -11675,7 +11683,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -11701,7 +11709,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -11727,7 +11735,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionSubmit( + expect(tracker.trackProductInsightsAgentQuestionSubmit( Object.assign(requiredParameters, optionalParameters), )).to.equal(true); }); @@ -11735,13 +11743,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpQuestionSubmit()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentQuestionSubmit()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpQuestionSubmit()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentQuestionSubmit()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -11766,7 +11774,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -11791,7 +11799,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -11806,7 +11814,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -11823,7 +11831,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); } @@ -11851,7 +11859,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -11879,11 +11887,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpQuestionSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); }); - describe('trackAssistantPdpAnswerView', () => { + describe('trackProductInsightsAgentAnswerView', () => { const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', answerText: 'This product is awesome!' }; const optionalParameters = { section: 'Products', @@ -11921,7 +11929,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -11947,7 +11955,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -11973,7 +11981,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -11999,7 +12007,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -12026,19 +12034,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerView(Object.assign(requiredParameters, optionalParameters))).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView( + Object.assign(requiredParameters, optionalParameters), + )).to.equal(true); }); it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpAnswerView()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentAnswerView()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpAnswerView()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentAnswerView()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -12063,7 +12073,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -12088,7 +12098,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -12103,7 +12113,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerView(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -12120,7 +12130,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); } @@ -12148,7 +12158,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -12176,11 +12186,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerView(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); }); - describe('trackAssistantPdpAnswerFeedback', () => { + describe('trackProductInsightsAgentAnswerFeedback', () => { const requiredParameters = { itemId: '1', itemName: 'item1', feedbackLabel: 'thumbs_up' }; const optionalParameters = { section: 'Products', @@ -12217,7 +12227,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { @@ -12243,7 +12253,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and userId are provided', (done) => { @@ -12269,7 +12279,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required parameters and testCells are provided', (done) => { @@ -12295,7 +12305,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); it('Should respond with a valid response when required and optional parameters are provided', (done) => { @@ -12321,7 +12331,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerFeedback( + expect(tracker.trackProductInsightsAgentAnswerFeedback( Object.assign(requiredParameters, optionalParameters), )).to.equal(true); }); @@ -12329,13 +12339,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpAnswerFeedback()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentAnswerFeedback()).to.be.an('error'); }); it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantPdpAnswerFeedback()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentAnswerFeedback()).to.be.an('error'); }); it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { @@ -12360,7 +12370,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { @@ -12385,7 +12395,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { @@ -12400,7 +12410,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters, { timeout: 10 })).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters, { timeout: 10 })).to.equal(true); }); it('Should be rejected when global network request timeout is provided and reached', (done) => { @@ -12417,7 +12427,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); } @@ -12445,7 +12455,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); it('Should properly transform non-breaking spaces in parameters', (done) => { @@ -12473,7 +12483,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { done(); }); - expect(tracker.trackAssistantPdpAnswerFeedback(requiredParameters)).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); }); }); diff --git a/src/modules/tracker.js b/src/modules/tracker.js index a7eb1276..5344cb6c 100644 --- a/src/modules/tracker.js +++ b/src/modules/tracker.js @@ -2775,9 +2775,9 @@ class Tracker { } /** - * Send Assistant PDP view events + * Send product insights agent view events * - * @function trackAssistantPdpViews + * @function trackProductInsightsAgentViews * @param {object} parameters - Additional parameters to be sent with request * @param {array.<{question: string}>} parameters.questions - List of pre-defined questions shown to the user * @param {string} parameters.itemId - Product id whose page we are on @@ -2789,9 +2789,9 @@ class Tracker { * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} - * @description The PDP Q&A element appeared in the visible part of the page + * @description The product insights agent element appeared in the visible part of the page * @example - * constructorio.tracker.trackAssistantPdpViews({ + * constructorio.tracker.trackProductInsightsAgentViews({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -2814,7 +2814,7 @@ class Tracker { * }, * ); */ - trackAssistantPdpViews(parameters, networkParameters = {}) { + trackProductInsightsAgentViews(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_views?`; @@ -2861,9 +2861,9 @@ class Tracker { } /** - * Send Assistant PDP view event + * Send product insights agent view event * - * @function trackAssistantPdpView + * @function trackProductInsightsAgentView * @param {object} parameters - Additional parameters to be sent with request * @param {array.<{question: string}>} parameters.questions - List of pre-defined questions shown to the user * @param {string} parameters.itemId - Product id whose page we are on @@ -2873,9 +2873,9 @@ class Tracker { * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} - * @description The PDP Q&A element appeared in the visible part of the page + * @description The product insights agent element appeared in the visible part of the page * @example - * constructorio.tracker.trackAssistantPdpView({ + * constructorio.tracker.trackProductInsightsAgentView({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -2888,7 +2888,7 @@ class Tracker { * }, * ); */ - trackAssistantPdpView(parameters, networkParameters = {}) { + trackProductInsightsAgentView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_view?`; @@ -2933,9 +2933,9 @@ class Tracker { } /** - * Send Assistant PDP out of view event + * Send product insights agent out of view event * - * @function trackAssistantPdpOutOfView + * @function trackProductInsightsAgentOutOfView * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are on @@ -2944,9 +2944,9 @@ class Tracker { * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} - * @description The PDP Q&A element disappeared from the visible part of the page + * @description The product insights agent element disappeared from the visible part of the page * @example - * constructorio.tracker.trackAssistantPdpOutOfView({ + * constructorio.tracker.trackProductInsightsAgentOutOfView({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -2954,7 +2954,7 @@ class Tracker { * }, * ); */ - trackAssistantPdpOutOfView(parameters, networkParameters = {}) { + trackProductInsightsAgentOutOfView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_out_of_view?`; @@ -2997,9 +2997,9 @@ class Tracker { } /** - * Send Assistant PDP out of view event + * Send product insights agent out of view event * - * @function trackAssistantPdpFocus + * @function trackProductInsightsAgentFocus * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are on @@ -3008,9 +3008,9 @@ class Tracker { * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} - * @description User focused on the PDP Q&A input element + * @description User focused on the product insights agent input element * @example - * constructorio.tracker.trackAssistantPdpFocus({ + * constructorio.tracker.trackProductInsightsAgentFocus({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3018,7 +3018,7 @@ class Tracker { * }, * ); */ - trackAssistantPdpFocus(parameters, networkParameters = {}) { + trackProductInsightsAgentFocus(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_focus?`; @@ -3061,9 +3061,9 @@ class Tracker { } /** - * Send Assistant PDP question click event + * Send product insights agent question click event * - * @function trackAssistantPdpQuestionClick + * @function trackProductInsightsAgentQuestionClick * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are on @@ -3073,9 +3073,9 @@ class Tracker { * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} - * @description The PDP Q&A question that was clicked on + * @description The product insights agent question that was clicked on * @example - * constructorio.tracker.trackAssistantPdpQuestionClick({ + * constructorio.tracker.trackProductInsightsAgentQuestionClick({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3084,7 +3084,7 @@ class Tracker { * }, * ); */ - trackAssistantPdpQuestionClick(parameters, networkParameters = {}) { + trackProductInsightsAgentQuestionClick(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_question_click?`; @@ -3129,9 +3129,9 @@ class Tracker { } /** - * Send Assistant PDP question submit + * Send product insights agent question submit * - * @function trackAssistantPdpQuestionSubmit + * @function trackProductInsightsAgentQuestionSubmit * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are on @@ -3141,9 +3141,9 @@ class Tracker { * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} - * @description The PDP Q&A question was submitted + * @description The product insights agent question was submitted * @example - * constructorio.tracker.trackAssistantPdpQuestionSubmit({ + * constructorio.tracker.trackProductInsightsAgentQuestionSubmit({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3152,7 +3152,7 @@ class Tracker { * }, * ); */ - trackAssistantPdpQuestionSubmit(parameters, networkParameters = {}) { + trackProductInsightsAgentQuestionSubmit(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_question_submit?`; @@ -3197,9 +3197,9 @@ class Tracker { } /** - * Send Assistant PDP answer view + * Send product insights agent answer view * - * @function trackAssistantPdpAnswerView + * @function trackProductInsightsAgentAnswerView * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are on @@ -3211,9 +3211,9 @@ class Tracker { * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} - * @description The PDP Q&A answer was shown to the user + * @description The product insights agent answer was shown to the user * @example - * constructorio.tracker.trackAssistantPdpAnswerView({ + * constructorio.tracker.trackProductInsightsAgentAnswerView({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3224,7 +3224,7 @@ class Tracker { * }, * ); */ - trackAssistantPdpAnswerView(parameters, networkParameters = {}) { + trackProductInsightsAgentAnswerView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_answer_view?`; @@ -3273,9 +3273,9 @@ class Tracker { } /** - * Send Assistant PDP answer feedback + * Send product insights agent answer feedback * - * @function trackAssistantPdpAnswerFeedback + * @function trackProductInsightsAgentAnswerFeedback * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.itemId - Product id whose page we are on * @param {string} parameters.itemName - Product name whose page we are on @@ -3288,7 +3288,7 @@ class Tracker { * @returns {(true|Error)} * @description A user provided feedback on an answers usefulness * @example - * constructorio.tracker.trackAssistantPdpAnswerFeedback({ + * constructorio.tracker.trackProductInsightsAgentAnswerFeedback({ * { * 'itemId': '1', * 'itemName': 'item1', @@ -3298,7 +3298,7 @@ class Tracker { * }, * ); */ - trackAssistantPdpAnswerFeedback(parameters, networkParameters = {}) { + trackProductInsightsAgentAnswerFeedback(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_answer_feedback?`; diff --git a/src/types/tracker.d.ts b/src/types/tracker.d.ts index 600e6706..d508298a 100644 --- a/src/types/tracker.d.ts +++ b/src/types/tracker.d.ts @@ -331,7 +331,7 @@ declare class Tracker { networkParameters?: NetworkParameters ): true | Error; - trackAssistantPdpViews(parameters: { + trackProductInsightsAgentViews(parameters: { questions: Question[]; itemId: string; itemName: string; @@ -340,7 +340,7 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPdpView(parameters: { + trackProductInsightsAgentView(parameters: { questions: Question[]; itemId: string; itemName: string; @@ -348,21 +348,21 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPdpOutOfView(parameters: { + trackProductInsightsAgentOutOfView(parameters: { itemId: string; itemName: string; variationId?: string; section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPdpFocus(parameters: { + trackProductInsightsAgentFocus(parameters: { itemId: string; itemName: string; variationId?: string; section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPdpQuestionClick(parameters: { + trackProductInsightsAgentQuestionClick(parameters: { itemId: string; itemName: string; question: string; @@ -370,7 +370,7 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPdpQuestionSubmit(parameters: { + trackProductInsightsAgentQuestionSubmit(parameters: { itemId: string; itemName: string; question: string; @@ -378,7 +378,7 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPdpAnswerView(parameters: { + trackProductInsightsAgentAnswerView(parameters: { itemId: string; itemName: string; question: string; @@ -388,7 +388,7 @@ declare class Tracker { section?: string; }, networkParameters?: NetworkParameters): true | Error; - trackAssistantPdpAnswerFeedback(parameters: { + trackProductInsightsAgentAnswerFeedback(parameters: { itemId: string; itemName: string; feedbackLabel: string; From 057a02ada21e6dcb8147b12c5df297d57cfa6d77 Mon Sep 17 00:00:00 2001 From: Chris Gee Date: Tue, 1 Jul 2025 16:04:19 -0700 Subject: [PATCH 11/12] Correct descriptions --- src/modules/tracker.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/modules/tracker.js b/src/modules/tracker.js index 5344cb6c..32c98353 100644 --- a/src/modules/tracker.js +++ b/src/modules/tracker.js @@ -2997,7 +2997,7 @@ class Tracker { } /** - * Send product insights agent out of view event + * Send product insights agent input focus event * * @function trackProductInsightsAgentFocus * @param {object} parameters - Additional parameters to be sent with request @@ -3073,7 +3073,7 @@ class Tracker { * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} - * @description The product insights agent question that was clicked on + * @description User clicked on a question within the product insights agent * @example * constructorio.tracker.trackProductInsightsAgentQuestionClick({ * { @@ -3129,7 +3129,7 @@ class Tracker { } /** - * Send product insights agent question submit + * Send product insights agent question submit event * * @function trackProductInsightsAgentQuestionSubmit * @param {object} parameters - Additional parameters to be sent with request @@ -3141,7 +3141,7 @@ class Tracker { * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} - * @description The product insights agent question was submitted + * @description User submitted a question to the product insights agent * @example * constructorio.tracker.trackProductInsightsAgentQuestionSubmit({ * { @@ -3197,7 +3197,7 @@ class Tracker { } /** - * Send product insights agent answer view + * Send product insights agent answer view event * * @function trackProductInsightsAgentAnswerView * @param {object} parameters - Additional parameters to be sent with request @@ -3211,7 +3211,7 @@ class Tracker { * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} - * @description The product insights agent answer was shown to the user + * @description User viewed the answer provided by the product insights agent * @example * constructorio.tracker.trackProductInsightsAgentAnswerView({ * { @@ -3273,7 +3273,7 @@ class Tracker { } /** - * Send product insights agent answer feedback + * Send product insights agent answer feedback event * * @function trackProductInsightsAgentAnswerFeedback * @param {object} parameters - Additional parameters to be sent with request From 927e7fa310510f78756df76e6b3848e4d3394e60 Mon Sep 17 00:00:00 2001 From: Chris Gee Date: Thu, 10 Jul 2025 19:53:11 -0700 Subject: [PATCH 12/12] Name change --- src/modules/tracker.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/modules/tracker.js b/src/modules/tracker.js index 32c98353..75b03d65 100644 --- a/src/modules/tracker.js +++ b/src/modules/tracker.js @@ -2817,7 +2817,7 @@ class Tracker { trackProductInsightsAgentViews(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_views?`; + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/product_insights_agent_views?`; const { section, questions, @@ -2891,7 +2891,7 @@ class Tracker { trackProductInsightsAgentView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_view?`; + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/product_insights_agent_view?`; const { section, questions, @@ -2957,7 +2957,7 @@ class Tracker { trackProductInsightsAgentOutOfView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_out_of_view?`; + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/product_insights_agent_out_of_view?`; const { section, itemId, @@ -3021,7 +3021,7 @@ class Tracker { trackProductInsightsAgentFocus(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_focus?`; + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/product_insights_agent_focus?`; const { section, itemId, @@ -3087,7 +3087,7 @@ class Tracker { trackProductInsightsAgentQuestionClick(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_question_click?`; + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/product_insights_agent_question_click?`; const { section, itemId, @@ -3155,7 +3155,7 @@ class Tracker { trackProductInsightsAgentQuestionSubmit(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_question_submit?`; + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/product_insights_agent_question_submit?`; const { section, itemId, @@ -3227,7 +3227,7 @@ class Tracker { trackProductInsightsAgentAnswerView(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_answer_view?`; + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/product_insights_agent_answer_view?`; const { section, itemId, @@ -3301,7 +3301,7 @@ class Tracker { trackProductInsightsAgentAnswerFeedback(parameters, networkParameters = {}) { // Ensure parameters are provided (required) if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) { - const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/assistant_pdp_answer_feedback?`; + const baseUrl = `${this.options.serviceUrl}/v2/behavioral_action/product_insights_agent_answer_feedback?`; const { section, itemId,