Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for trigger conditions to remote survey questions #4051

Closed
felixarntz opened this issue Sep 15, 2021 · 3 comments
Closed

Add support for trigger conditions to remote survey questions #4051

felixarntz opened this issue Sep 15, 2021 · 3 comments
Labels
P0 High priority QA: Eng Requires specialized QA by an engineer Type: Enhancement Improvement of an existing feature
Milestone

Comments

@felixarntz
Copy link
Member

felixarntz commented Sep 15, 2021

Per requirement for the new Idea Hub survey, we need to make an additional enhancement to the surveys infrastructure itself: Currently it's only possible to show an alternate completion prompt based on an answer to a question. We now need to expand this functionality so that it works for follow-up questions as well.

This is a launch blocker for Idea Hub, even though it's overall a general survey issue.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • The survey infrastructure should receive support for conditionally displaying questions from the API response if they include the respective data specification. More specifically:
    • If a question object includes a trigger_condition array that is not empty, that question should only be shown if all of the trigger conditions are met.
    • The format of the trigger_condition array can be expected to be exactly the same as for the property of the same name that is already handled for completion prompts. In other words, the logic to handle that can partly be copied, just it should affect the question that it is set on.
    • In other words, if any of the trigger_condition entries does not evaluate to true based on the answers the current user has given, the question should be skipped and not displayed to the user.
    • No validation for whether a condition is actually "reasonable" needs to be included, this can be expected to always make sense from the API. For example, an question will never include a condition that is based on an answer to a question that would only show up afterwards, as that simply wouldn't make any sense. That also means technically that the first question (question_ordinal 1) will never have any trigger conditions, since there are no answers that could be based on.
    • Every question within a survey will still have a different question_ordinal, no question will have the same as another, in order to uniquely distinguish them. That means, going forward, for example the question with question_ordinal 2 may not necessarily be the second question that is displayed - if it has a trigger_condition that isn't satisfied, it would be skipped, so that essentially the following question (question_ordinal 3) would be the second question that is displayed.
  • A few examples to outline how this should work:
    • Let's say a survey starts with a rating question. There's another question with ordinal 2 that only shows for rating 4-5, and another question with ordinal 3 that only shows for ratings 1-2.
      • If the user rates 4, question 3 should be skipped.
      • If the user rates 2, question 2 should be skipped.
      • If the user rates 3, both questions should be skipped, i.e. after question 1 it should immediately go to the completion prompt.
    • Another example, now with a single_select question as first item with two options yes and no. There's another question with ordinal 2 that only shows if the user answered the first question with yes, and also another question with ordinal 3 that only shows if the user answered the second question with yes.
      • If the user answers yes to question 1, question 2 should be shown.
      • If the user answers yes to question 2, question 3 should be shown.
      • If the user answers no to question 1, both question 2 and 3 should be skipped.

Implementation Brief

The API infrastructure is currently being built. Depending on how quickly this gets implemented, the Site Kit Service part may not be ready yet. Please coordinate testing with @felixarntz.

  • The questions variable created in
    const questions = useSelect( ( select ) =>
    select( CORE_USER ).getCurrentSurveyQuestions()
    );
    should be further modified/filtered when used in the rest of the component to only return the questions either:
    • with no trigger_condition value
    • with trigger_condition values that are met by the existing survey data, using the completions variable in the component selected from the data store. Note that each trigger_condition shape will be the same as the conditions in completions, see
      completion: [
      {
      completion_ordinal: 1,
      completion_title: 'Thanks for sharing your thoughts!',
      completion_text:
      'We’re glad Site Kit is helpful for you! To help others discover it too, take a moment to share your opinion as a review.',
      follow_up_text: 'Let’s go',
      follow_up_url: '#new-url',
      trigger_condition: [
      {
      question_ordinal: 1,
      answer_ordinal: [ 1, 2, 3, 4, 5 ],
      },
      ],
      },
      ],
      for an example
  • It would make the most sense to rename questions to potentialQuestions then declare questions below it based on the filtering described above, so other code can be kept consistent.

Test Coverage

  • Add tests to assets/js/components/surveys/CurrentSurvey.test.js to ensure the above described behaviour is working.

QA Brief

Changelog entry

  • Add new conditional follow-up questions to user surveys.
@felixarntz felixarntz added P0 High priority Type: Enhancement Improvement of an existing feature QA: Eng Requires specialized QA by an engineer labels Sep 15, 2021
@felixarntz felixarntz added this to the Sprint 58 milestone Sep 15, 2021
@felixarntz felixarntz self-assigned this Sep 15, 2021
@felixarntz felixarntz removed their assignment Sep 15, 2021
@tofumatt tofumatt assigned tofumatt and unassigned tofumatt Sep 16, 2021
@eugene-manuilov eugene-manuilov self-assigned this Sep 17, 2021
@eugene-manuilov
Copy link
Collaborator

IB ✔️

@kuasha420
Copy link
Collaborator

QA: ✔️

On the storybook, correct follow up question and/or completion appears based the value of first answer. It matches with the test case and AC.

Pinging @wpdarren for for final rounds of QA and next step.

@kuasha420 kuasha420 removed their assignment Sep 23, 2021
@wpdarren
Copy link
Collaborator

@kuasha420 I have picked up my QA on 4052, so if you are happy with this, I shall move to approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 High priority QA: Eng Requires specialized QA by an engineer Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

6 participants