Skip to content

Commit fb31be3

Browse files
[NO-REF] - introduce skip tracking param for quiz next question (#413)
* [NO-REF] - introduce skip tracking param for quiz next question * Remove only for test * Update types and jsdoc
1 parent 9e6e9df commit fb31be3

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

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('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] - If true, tracking for this question will be skipped. This is useful for preloading the first question of a 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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export interface QuizzesParameters {
2121
quizSessionId?: string;
2222
}
2323

24+
export interface NextQuestionQuizzesParameters extends QuizzesParameters {
25+
skipTracking?: boolean;
26+
}
27+
2428
export interface QuizResultsFmtOptions {
2529
hidden_fields?: string[];
2630
fields?: string[];
@@ -42,7 +46,7 @@ declare class Quizzes {
4246

4347
getQuizNextQuestion(
4448
quizId: string,
45-
parameters?: QuizzesParameters,
49+
parameters?: NextQuestionQuizzesParameters,
4650
networkParameters?: NetworkParameters
4751
): Promise<NextQuestionResponse>;
4852

0 commit comments

Comments
 (0)