site-kit-wp: Implement HaTS survey triggers for users who answers "Other" to any User Input question

Feature Description

Since we’re removing the text field next to the “Other” in all the User Input questions in #6181, we should implement surveys for users who answer other to get more information on their choice. This can be a single survey or multiple surveys, whichever is best UX.

Related Asana Task: https://app.asana.com/0/1201538818998708/1203393984679795


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

Acceptance criteria

  • A survey should be triggered for users who answer “Other” to at least one of the User Input questions.
  • This should only be triggered once user completes answering the questions.
    • This should also trigger after user edits user input question and at least one of the answers changes to “Other”.
  • For sites with multiple admins, the survey will only appear to the admin who answered the question. This is regardless whether the question is user or site specific.
  • Since there are three user input questions and user can answer Other to any combination of them, one of the following trigger IDs should be used based on the answer.
    • userInput_answered_other__purpose
    • userInput_answered_other__postFrequency
    • userInput_answered_other__goals
    • userInput_answered_other__purpose_postFrequency
    • userInput_answered_other__purpose_goals
    • userInput_answered_other__postFrequency_goals
    • userInput_answered_other__purpose_postFrequency_goals
  • The the survey returned from the Service will be queued and shown to the user as part of #6306.

Implementation Brief

  • Create a new action maybeTriggerUserInputSurvey action in CORE_USER store.
    • Get the current user input settings using the getUserInputSettings selector.
    • If there is at least one submitted answer contains other-
      • Construct one of the survey triggerID mentioned in the AC.
      • Using the triggerSurvey action from CORE_USER trigger the survey for the user using the aforementioned triggerID.
  • Update the saveUserInputSettings action of CORE_USER:
    • If there was no error, before setting isSaving to false, yield the maybeTriggerUserInputSurvey action.
  • In addition to triggering the survey, we need to also make sure any existing outdated surveys in the Survey_Queue is dequeued. For that:
    • In Google\Site_Kit\Core\User_Input\REST_User_Input_Controller class:
      • Add a protected $survey_queue instance variable which will be received and assigned in the constructor.
      • In POST:core/user/data/user-input-settings rest route:
        • Before returning the return value of rest_ensure_response check if it’s a WP_REST_Response.
        • Dequeue user_input_answered_other_survey survey using the $survey_queue->dequeue( survey_id ).
          • (Note: This is the preliminary survey_id for all userInput “other” surveys )
    • In Google\Site_Kit\Core\User_Input\User_Input class:
      • In the constructor, pass a new Survey_Queue instance while creating the REST_User_Input_Controller class instance.

Test Coverage

  • Add tests for maybeTriggerUserInputSurvey action.
  • Add test coverage for saveUserInputSettings action.
  • Add test coverage for the above PHP changes.

QA Brief

  • Set up a new site, install, and connect Site KIt.
  • Using the tester plugin, enable the userInput feature flag.
  • Go to the /wp-admin/admin.php?page=googlesitekit-user-input screen. Answer the user input questions and answer “Other” for one or more questions.
  • In the User Input preview screen, open your browser developer tools and go to the “Network” tab. Ensure that network log recording is on so that network requests persist even though you get navigated to a different screen.
  • Click “Save”.
  • Ensure that you see a request to the /wp-json/google-site-kit/v1/core/user/data/survey-trigger?_locale=user endpoint that has {"data":{"triggerID":"userInput_answered_other__[TRIGGER_ID]"}} in payload.
  • The TRIGGER_ID placeholder above should include slug of questions that you have answered “Other” for, according to the ACs.
  • Answer the questions again but do not choose “Other” this time. Verify that the above network request is not made in this case.

Changelog entry

  • Implement HaTS survey triggers for users who answers “Other” to any User Input question

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks @kuasha420 – I tweaked the name of the survey id but otherwise this looks good to me 👍

IB ✅

@aaemnnosttv Thank you for the review but this was the previous iteration of the IB before we had the call.

As par our slack discussion, I’ve updated the IB to unconditionally dequeue the userInput_answered_other survey from the Survey_Queue after User Input Settings is saved. Any potential survey will get triggered afterwards from client-side, so as long as service keeps returning the (incomplete) survey, this approach should be perfectly fine and also make sure any pending survey is dequeued when the new answer doesn’t contain other.

Please have a look. I’ll also keep @eugene-manuilov assigned here so he can confirm the detail about the service related detail I mentioned above.

Thank you both for all your help, I feel we’re very close to finalizing this!

Cheers.

@kuasha420 👋 Since we’ll be coming back to KMW and UIV2 over the next few sprints, I’m going to assign this one over to you for an IB so we can pick it up soon. Thanks!

@bethanylang This one is still blocked by 6306, however we had a call just before the break and made some decisions and progress on it. There’s a doc about it in the open slack channel and @aaemnnosttv is working on adding preliminary ACs to #6306. Once it moves forward, we will revisit this issue. Cheers!

@kuasha420 Today @aaemnnosttv @eugene-manuilov and I discussed in a dashboard sharing survey related meeting some enhancements that we need to make to the survey triggering infrastructure to support event-based surveys better. This will also affect how to trigger this survey here. I would therefore suggest to pause the work on this issue until we have finalized that approach. I will loop you in that conversation.

@bethanylang Added label!