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

Current selection can pull metrics list from previous answer #10034

Closed
2 tasks
wpdarren opened this issue Jan 16, 2025 · 6 comments
Closed
2 tasks

Current selection can pull metrics list from previous answer #10034

wpdarren opened this issue Jan 16, 2025 · 6 comments
Labels
Module: Analytics Google Analytics module related issues P0 High priority Team S Issues for Squad 1 Type: Bug Something isn't working

Comments

@wpdarren
Copy link
Collaborator

wpdarren commented Jan 16, 2025

Bug Description

ACR Bug bash ticket in Asana can be found here. The second part of this ticket can be found in Asana here.

When tailored metrics site purpose answer is edited, if for example currently saved answer is Sell products, then you choose Publish a blog, and then go to Provide services and click on the Apply changes CTA current metrics selection is not pulling the current selection.

Screen.Recording.2025-01-14.at.15.22.49.mov

What changing the answer to the "What is the main purpose of the site?" question in the Settings page, the list of current metrics changes unexpectedly while the modal is saving.

For example when changing from "Sell products" to "Publish a blog", the modal opens up with this list of current metrics:

image.png

When the "Update metrics selection" CTA is clicked the list of current metrics is updated to the following while the selection is being saved:

image.png

Changing the answer again in order to show the modal, the current metrics are now as expected (i.e. the "New tailored metrics" list in the first modal):

image.png


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

Acceptance criteria

  • Switching between site purpose answers in the admin settings, and trying to apply changes should always trigger the modal with correct metrics in the current selection
    • It should accurately show tailored list of metrics for saved answer - reflecting what's currently in the suggested list
    • It should persist the current suggested metrics during saving/after saving is done, when Update metrics selection CTA is clicked

Implementation Brief

  • Update assets/js/components/KeyMetrics/ConfirmSitePurposeChangeModal.js
    • Source the value of currently saved purpose from CORE_USER datastore using getSavedUserInputSettings selector, for the existing savedPurpose
    • Replace the savedPurpose[ 0 ] argument in getAnswerBasedMetrics
      return select( CORE_USER ).getAnswerBasedMetrics( savedPurpose[ 0 ] );
      with savedPurpose?.purpose?.values?.[ 0 ]
  • In assets/js/components/user-input/UserInputPreview.js
    • Apply same changes as above, by sourcing different value for savedPurpose and using it in getAnswerBasedMetrics selector for currentMetrics
    • Rename the variable to savedPurposeSnapshot and source the value from USER_INPUT_QUESTIONS_PURPOSE key of the FORM_USER_INPUT_QUESTION_SNAPSHOT form like it was before for now modified savedPurpose
    • Update
      const newMetrics = useSelect( ( select ) => {
      return select( CORE_USER ).getKeyMetrics();
      } );
      selector, it should also include potential new events if they are detected using the same arguments/approach as here
      const includeConversionTailoredMetrics = useSelect( ( select ) => {
      const isGA4Connected =
      select( CORE_MODULES ).isModuleConnected( 'analytics-4' );
      if ( ! isGA4Connected ) {
      return false;
      }
      const haveConversionEventsForTailoredMetrics =
      select(
      MODULES_ANALYTICS_4
      ).haveConversionEventsForTailoredMetrics();
      if ( haveConversionEventsForTailoredMetrics ) {
      return select( MODULES_ANALYTICS_4 ).getDetectedEvents() || [];
      }
      return [];
      } );
      const newMetrics = useSelect( ( select ) => {
      return select( CORE_USER ).getAnswerBasedMetrics(
      null,
      includeConversionTailoredMetrics
      );
      } );
      • You can extract logic from includeConversionTailoredMetrics and add it as a new selector, say shouldIncludeConversionTailoredMetrics in assets/js/modules/analytics-4/datastore/conversion-reporting.js so it can be re-used in both files
  • Existing logic around FORM_USER_INPUT_QUESTION_SNAPSHOT form value should remain in other parts of the codebase, as it is primary used for accurately reseting the focus after modal changes as most reliable value.

Test Coverage

  • Update assets/js/components/KeyMetrics/ConfirmSitePurposeChangeModal.stories.js stories by using setUserInputSetting action to change site purpose

QA Brief

  • Setup Site Kit with Analytics module and conversionReporting feature flag enabled
  • Setup KMW using tailored metrics
  • Go to settings and edit site purpose - change site purpose few times before clicking apply CTA
  • Verify that current mtrics are correctly representing available suggested metrics based on currently saved metrics, not the wrong list of metrics
  • Verify that current metrics is remaining the same during the saving

Changelog entry

  • Fix bug that could cause metrics not to update properly if answers were changed several times before saving changes.
@wpdarren wpdarren added Module: Analytics Google Analytics module related issues P0 High priority Type: Bug Something isn't working labels Jan 16, 2025
@zutigrm zutigrm self-assigned this Jan 16, 2025
@binnieshah binnieshah added the Team S Issues for Squad 1 label Jan 17, 2025
@zutigrm zutigrm assigned zutigrm and unassigned zutigrm Jan 20, 2025
@10upsimon 10upsimon self-assigned this Jan 22, 2025
@10upsimon
Copy link
Collaborator

@zutigrm IB LGTM ✅ This one took a while for me to get my head around. Given that we're both very close to the form snapshot approach, let's aim to keep this issue amongst us if possible.

@10upsimon 10upsimon removed their assignment Jan 23, 2025
@zutigrm zutigrm self-assigned this Jan 24, 2025
@zutigrm zutigrm removed their assignment Jan 27, 2025
@tofumatt tofumatt assigned tofumatt and unassigned tofumatt Jan 29, 2025
@kelvinballoo kelvinballoo self-assigned this Jan 30, 2025
@kelvinballoo
Copy link
Collaborator

QA Update ⚠

I noticed a regression which is better explained through video.

Please refer to the attached video.

10034.test.wrong.mov

@zutigrm zutigrm removed their assignment Jan 30, 2025
@10upsimon 10upsimon assigned 10upsimon and zutigrm and unassigned 10upsimon Feb 4, 2025
@zutigrm zutigrm assigned 10upsimon and unassigned zutigrm Feb 4, 2025
@10upsimon 10upsimon removed their assignment Feb 4, 2025
@10upsimon
Copy link
Collaborator

@tofumatt this one is back with you for Merge Review given that it's targeted against main for release 1.146.0. Thanks!

@tofumatt tofumatt assigned kelvinballoo and unassigned tofumatt Feb 4, 2025
@kelvinballoo
Copy link
Collaborator

kelvinballoo commented Feb 6, 2025

QA Update ⚠

Thanks @zutigrm .

Tested the main regression I noticed before and this is now working as expected. Changing of site purpose is also displaying the modal with the correct metrics. Tested a few of those site purpose and not only what is on the video attached. ✅

10034.new.-.01.mov
_____________________________________________________________________________

🚨 That said I want to raise 2 other items. These are possibly out of scope for this ticket.
We can raise new tickets for those if you agree.

ITEM 1:
When Site purpose is 'Other', current metrics are understandably blank.
In that case, I think it's best to hide the 'Suggested tab' because it's blank but it will write 'No metrics were selected yet'.

Image
____________________________________________________________________

ITEM 2:
Here's the scenario:

  • Let's say we select a particular metric e.g. Publish a Blog.

  • If we change the site purpose to 'Other'

  • It will save straightaway without any popup modal. I assume that's ok because technically there is no metrics associated with it.

    • Can you confirm this though? Because on 'Latest Release' branch, a modal would pop up with current metrics as blank. This looks like a regression.
  • Now, if I change the site purpose to 'Publish a Blog' again, a modal would popup with the same current and new metrics.

  • I was not expecting this.

    Image

A video is attached for reference for both issues.
Note: those were tested on both develop and main branch.

10034.issues.mov

@zutigrm
Copy link
Collaborator

zutigrm commented Feb 6, 2025

@kelvinballoo Thanks,

I have opened a new issue #10182 to define handling of other for both cases (item 1 and item 2), since this issue fixes persisting the lists in confirm modal, the new one will define the fix for parts of the logic detecting the difference extending on the new logic introduced here.

For item 2 I also raised this with Sigal, to see if we want to include some message instead of showing empty list, etc

@zutigrm zutigrm removed their assignment Feb 6, 2025
@kelvinballoo
Copy link
Collaborator

QA update ✅

Thanks @zutigrm . Noted on that.

Moving ticket to approval since the main regression is now working as expected. Changing of site purpose is also displaying the modal with the correct metrics.
Tested good on a few of those site purpose and not only what is on the video attached. ✅

10034.new.-.01.mov

@kelvinballoo kelvinballoo removed their assignment Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: Analytics Google Analytics module related issues P0 High priority Team S Issues for Squad 1 Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants