From d8037ffdf2af8862302f621e7b4fde7d640ebcc0 Mon Sep 17 00:00:00 2001 From: Vlad Saitov Date: Thu, 13 Nov 2025 15:24:19 +0500 Subject: [PATCH 1/3] [NO-REF] - introduce skip tracking param for quiz next question --- spec/src/modules/quizzes.js | 13 +++++++++++++ src/modules/quizzes.js | 7 ++++++- src/types/quizzes.d.ts | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/spec/src/modules/quizzes.js b/spec/src/modules/quizzes.js index 6ccd1201..7d0e8b27 100644 --- a/spec/src/modules/quizzes.js +++ b/spec/src/modules/quizzes.js @@ -281,6 +281,19 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { }); }); + it.only('Should skip tracking', () => { + const { quizzes } = new ConstructorIO({ + apiKey: quizApiKey, + fetch: fetchSpy, + }); + + return quizzes.getQuizNextQuestion(validQuizId, { answers: validAnswers, skipTracking: true }).then(() => { + const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + expect(requestedUrlParams).to.have.property('skip_tracking').to.equal('true'); + }); + }); + it('Should be rejected if an invalid quizVersionId is provided', () => { const { quizzes } = new ConstructorIO({ apiKey: quizApiKey, diff --git a/src/modules/quizzes.js b/src/modules/quizzes.js index 24e2f1d7..a1b82af6 100644 --- a/src/modules/quizzes.js +++ b/src/modules/quizzes.js @@ -42,7 +42,7 @@ function createQuizUrl(quizId, parameters, options, path) { } if (parameters) { - const { section, answers, quizSessionId, quizVersionId, page, resultsPerPage, filters, fmtOptions, hiddenFields } = parameters; + const { section, answers, quizSessionId, quizVersionId, page, resultsPerPage, filters, fmtOptions, hiddenFields, skipTracking } = parameters; // Pull section from parameters if (section) { @@ -89,6 +89,10 @@ function createQuizUrl(quizId, parameters, options, path) { queryParams.fmt_options = { hidden_fields: hiddenFields }; } } + + if (skipTracking) { + queryParams.skip_tracking = skipTracking; + } } queryParams._dt = Date.now(); @@ -123,6 +127,7 @@ class Quizzes { * @param {array} [parameters.answers] - An array of answers in the format [[1,2], [1], ["true"], ["seen"], [""]]. Based on the question type, answers should either be an integer, "true"/"false", "seen" or an empty string ("") if skipped * @param {string} [parameters.quizVersionId] - Version identifier for the quiz. Version ID will be returned with the first request and it should be passed with subsequent requests. More information can be found: https://docs.constructor.com/reference/configuration-quizzes * @param {string} [parameters.quizSessionId] - Session identifier for the quiz. Session ID will be returned with the first request and it should be passed with subsequent requests. More information can be found: https://docs.constructor.com/reference/configuration-quizzes + * @param {boolean} [parameters.skipTracking] - Boolean value indicating if tracking for this question has to be skipped. Might be useful, when you are willing to preload first question of the quiz. * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {Promise} diff --git a/src/types/quizzes.d.ts b/src/types/quizzes.d.ts index be69aba0..6623aa45 100644 --- a/src/types/quizzes.d.ts +++ b/src/types/quizzes.d.ts @@ -19,6 +19,7 @@ export interface QuizzesParameters { answers?: any[]; quizVersionId?: string; quizSessionId?: string; + skipTracking?: boolean; } export interface QuizResultsFmtOptions { From c61f88c96f9c0494769993f9759a4972e22b44a9 Mon Sep 17 00:00:00 2001 From: Vlad Saitov Date: Thu, 13 Nov 2025 15:35:05 +0500 Subject: [PATCH 2/3] Remove only for test --- spec/src/modules/quizzes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/src/modules/quizzes.js b/spec/src/modules/quizzes.js index 7d0e8b27..927153bb 100644 --- a/spec/src/modules/quizzes.js +++ b/spec/src/modules/quizzes.js @@ -281,7 +281,7 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { }); }); - it.only('Should skip tracking', () => { + it('Should skip tracking', () => { const { quizzes } = new ConstructorIO({ apiKey: quizApiKey, fetch: fetchSpy, From 062f4797a38f8facb93348bcc3c2f015bf5e018c Mon Sep 17 00:00:00 2001 From: Vlad Saitov Date: Mon, 17 Nov 2025 15:27:26 +0500 Subject: [PATCH 3/3] Update types and jsdoc --- src/modules/quizzes.js | 2 +- src/types/quizzes.d.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/quizzes.js b/src/modules/quizzes.js index a1b82af6..e8bbb9db 100644 --- a/src/modules/quizzes.js +++ b/src/modules/quizzes.js @@ -127,7 +127,7 @@ class Quizzes { * @param {array} [parameters.answers] - An array of answers in the format [[1,2], [1], ["true"], ["seen"], [""]]. Based on the question type, answers should either be an integer, "true"/"false", "seen" or an empty string ("") if skipped * @param {string} [parameters.quizVersionId] - Version identifier for the quiz. Version ID will be returned with the first request and it should be passed with subsequent requests. More information can be found: https://docs.constructor.com/reference/configuration-quizzes * @param {string} [parameters.quizSessionId] - Session identifier for the quiz. Session ID will be returned with the first request and it should be passed with subsequent requests. More information can be found: https://docs.constructor.com/reference/configuration-quizzes - * @param {boolean} [parameters.skipTracking] - Boolean value indicating if tracking for this question has to be skipped. Might be useful, when you are willing to preload first question of the quiz. + * @param {boolean} [parameters.skipTracking] - If true, tracking for this question will be skipped. This is useful for preloading the first question of a quiz * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {Promise} diff --git a/src/types/quizzes.d.ts b/src/types/quizzes.d.ts index 6623aa45..057a1e34 100644 --- a/src/types/quizzes.d.ts +++ b/src/types/quizzes.d.ts @@ -19,6 +19,9 @@ export interface QuizzesParameters { answers?: any[]; quizVersionId?: string; quizSessionId?: string; +} + +export interface NextQuestionQuizzesParameters extends QuizzesParameters { skipTracking?: boolean; } @@ -43,7 +46,7 @@ declare class Quizzes { getQuizNextQuestion( quizId: string, - parameters?: QuizzesParameters, + parameters?: NextQuestionQuizzesParameters, networkParameters?: NetworkParameters ): Promise;