Skip to content
Merged
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
13 changes: 13 additions & 0 deletions spec/src/modules/quizzes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/modules/quizzes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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}
Expand Down
6 changes: 5 additions & 1 deletion src/types/quizzes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface QuizzesParameters {
quizSessionId?: string;
}

export interface NextQuestionQuizzesParameters extends QuizzesParameters {
skipTracking?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed we use QuizzesParameters in functions other than getQuizNextQuestion. We should either omit it other places or have a separate type that extends this on for getQuizNextQuestion

}

export interface QuizResultsFmtOptions {
hidden_fields?: string[];
fields?: string[];
Expand All @@ -42,7 +46,7 @@ declare class Quizzes {

getQuizNextQuestion(
quizId: string,
parameters?: QuizzesParameters,
parameters?: NextQuestionQuizzesParameters,
networkParameters?: NetworkParameters
): Promise<NextQuestionResponse>;

Expand Down
Loading