Skip to content

Commit d8037ff

Browse files
[NO-REF] - introduce skip tracking param for quiz next question
1 parent d1e7182 commit d8037ff

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

spec/src/modules/quizzes.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,19 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => {
281281
});
282282
});
283283

284+
it.only('Should skip tracking', () => {
285+
const { quizzes } = new ConstructorIO({
286+
apiKey: quizApiKey,
287+
fetch: fetchSpy,
288+
});
289+
290+
return quizzes.getQuizNextQuestion(validQuizId, { answers: validAnswers, skipTracking: true }).then(() => {
291+
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);
292+
293+
expect(requestedUrlParams).to.have.property('skip_tracking').to.equal('true');
294+
});
295+
});
296+
284297
it('Should be rejected if an invalid quizVersionId is provided', () => {
285298
const { quizzes } = new ConstructorIO({
286299
apiKey: quizApiKey,

src/modules/quizzes.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function createQuizUrl(quizId, parameters, options, path) {
4242
}
4343

4444
if (parameters) {
45-
const { section, answers, quizSessionId, quizVersionId, page, resultsPerPage, filters, fmtOptions, hiddenFields } = parameters;
45+
const { section, answers, quizSessionId, quizVersionId, page, resultsPerPage, filters, fmtOptions, hiddenFields, skipTracking } = parameters;
4646

4747
// Pull section from parameters
4848
if (section) {
@@ -89,6 +89,10 @@ function createQuizUrl(quizId, parameters, options, path) {
8989
queryParams.fmt_options = { hidden_fields: hiddenFields };
9090
}
9191
}
92+
93+
if (skipTracking) {
94+
queryParams.skip_tracking = skipTracking;
95+
}
9296
}
9397

9498
queryParams._dt = Date.now();
@@ -123,6 +127,7 @@ class Quizzes {
123127
* @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
124128
* @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
125129
* @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
130+
* @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.
126131
* @param {object} [networkParameters] - Parameters relevant to the network request
127132
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
128133
* @returns {Promise}

src/types/quizzes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface QuizzesParameters {
1919
answers?: any[];
2020
quizVersionId?: string;
2121
quizSessionId?: string;
22+
skipTracking?: boolean;
2223
}
2324

2425
export interface QuizResultsFmtOptions {

0 commit comments

Comments
 (0)