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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spec/src/modules/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9836,6 +9836,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
const optionalParameters = {
section: 'Products',
threadId: 'thread-1234',
source: 'suggestion',
};

it('Should respond with a valid response when intent and required parameters are provided', (done) => {
Expand Down Expand Up @@ -9985,6 +9986,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('section').to.equal('Products');
expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId);
expect(requestParams).to.have.property('source').to.equal(optionalParameters.source);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
Expand Down
10 changes: 9 additions & 1 deletion src/modules/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2738,15 +2738,18 @@ class Tracker {
* @param {string} parameters.intent - Intent of user request
* @param {string} [parameters.section] - The section name for the item Ex. "Products"
* @param {string} [parameters.threadId] - Thread ID for grouping events within a conversation
* @param {string} [parameters.source] - How the intent was submitted Ex. "suggestion"
* @param {object} [networkParameters] - Parameters relevant to the network request
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
* @returns {(true|Error)}
* @description User submitted an agent search
* (pressing enter within agent input element, or clicking agent submit element)
* (pressing enter within agent input element, or clicking an agent submit or
* suggested question element)
* @example
* constructorio.tracker.trackAgentSubmit(
* {
* intent: 'show me a recipe for a cookie',
* source: 'suggestion',
* },
* );
*/
Expand All @@ -2758,6 +2761,7 @@ class Tracker {
section,
intent,
threadId,
source,
} = parameters;
const bodyParams = {
intent,
Expand All @@ -2768,6 +2772,10 @@ class Tracker {
bodyParams.thread_id = threadId;
}

if (source) {
bodyParams.source = source;
}

const requestURL = `${baseUrl}${applyParamsAsString({}, this.options)}`;
const requestMethod = 'POST';
const requestBody = applyParams(bodyParams, {
Expand Down
1 change: 1 addition & 0 deletions src/types/tracker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ declare class Tracker {
intent: string;
section?: string;
threadId?: string;
source?: string;
},
networkParameters?: NetworkParameters
): true | Error;
Expand Down
Loading