diff --git a/spec/src/modules/quizzes.js b/spec/src/modules/quizzes.js index 6ccd1201..927153bb 100644 --- a/spec/src/modules/quizzes.js +++ b/spec/src/modules/quizzes.js @@ -281,6 +281,19 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { }); }); + it('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..e8bbb9db 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] - 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 be69aba0..057a1e34 100644 --- a/src/types/quizzes.d.ts +++ b/src/types/quizzes.d.ts @@ -21,6 +21,10 @@ export interface QuizzesParameters { quizSessionId?: string; } +export interface NextQuestionQuizzesParameters extends QuizzesParameters { + skipTracking?: boolean; +} + export interface QuizResultsFmtOptions { hidden_fields?: string[]; fields?: string[]; @@ -42,7 +46,7 @@ declare class Quizzes { getQuizNextQuestion( quizId: string, - parameters?: QuizzesParameters, + parameters?: NextQuestionQuizzesParameters, networkParameters?: NetworkParameters ): Promise;