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

When enabling groups the Analytics edit scope is requested even when it won't be needed #9595

Closed
1 task
techanvil opened this issue Nov 1, 2024 · 2 comments
Labels
Feature: Audiences Module: Analytics Google Analytics module related issues Needs Documentation Issues which require new or updated public-facing documentation. P1 Medium priority Team M Issues for Squad 2 Type: Enhancement Improvement of an existing feature

Comments

@techanvil
Copy link
Collaborator

techanvil commented Nov 1, 2024

Feature Description

The Analytics edit scope is only required when creating an audience or custom dimension, but it's always requested if not present when setting up the feature via one of the Enable groups CTAs.

This could be avoided by first syncing the audiences and custom dimensions and determining if any need to be created, and then only entering the OAuth flow to request the scope if necessary.

See the related Asana task.


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

Acceptance criteria

  • When clicking on Enable groups to set up Audience Segmentation, from either the Setup CTA on the dashboard or the Settings screen, with the Analytics edit scope not currently granted:
    • The Analytics edit scope should only be requested if it's determined that an audience or the googlesitekit_post_type custom dimension need to be created.
    • The OAuth flow should not be entered if this is not the case.

Implementation Brief

  • Update assets/js/modules/analytics-4/hooks/useEnableAudienceGroup.js:
    • Within the onEnableGroups useCallback:
    • Check if new audiences need to be created:
      • Call await syncAvailableAudiences().
      • Get the list of audiences using the getAvailableAudiences selector.
      • Check the audience list for each of the following audiences looping through them and checking each with .find returning true the first time an audiences is missing, otherwise return false, call this boolean requiresNewAudienceCreation:
    • Check if the custom post type dimension needs to be created:
      • Get the list of custom dimensions using the getAvailableCustomDimensions selector.
      • Check the custom dimensions list for the googlesitekit_post_type key using .find, negate the response of the find and call this boolean requiresPostTypeCustomAudienceCreation.
    • Update the condition which triggers the new permission request to take into account these new conditions:
       if ( ! hasAnalytics4EditScope && ( requiresNewAudienceCreation || requiresPostTypeCustomAudienceCreation ) {
      
      const requiredAudienceSlugs = [
      'new-visitors',
      'returning-visitors',
      ];

Test Coverage

  • Add tests in assets/js/modules/analytics-4/hooks/useEnableAudienceGroup.test.js to confirm additional permissions are only requested when the AC conditions are met.

QA Brief

  • Turn on the audienceSegmentation feature flag.
  • Set up Site Kit.
  • Set up the Analytics module with a property that already has the "New visitors" and "Returning visitors" audiences (and/or one or more user defined audiences with data over the past 90 days), as well as the googlesitekit_post_type custom dimension.
    • This can be achieved by using a property that already had Audience Segmentation set up before.
  • Go to the Site Kit dashboard and observe the Audience Segmentation setup CTA banner.
  • Click on the "Enable groups" CTA. Verify that even though the user does not have the Analytics edit scope, it will not redirect you to OAuth.
  • Try the same with a different property that does not have any non-default audiences and/or the googlesitekit_post_type custom dimension set up. Verify that it does redirect you to OAuth now.
  • Refer to the QAB for Implement the unhappy paths for the Setup CTA Banner #8134 and verify that the error modal still appears in unhappy path scenarios.
  • Run through a similar set of tests, but enable the feature from the Settings > Admin Settings > Visitor groups > Enable groups CTA.

Changelog entry

  • When enabling groups, ensure Analytics scope is only requested when needed.
@techanvil techanvil added Feature: Audiences Module: Analytics Google Analytics module related issues P1 Medium priority Type: Enhancement Improvement of an existing feature labels Nov 1, 2024
@techanvil techanvil assigned techanvil and unassigned techanvil Nov 6, 2024
@jamesozzie jamesozzie added the Needs Documentation Issues which require new or updated public-facing documentation. label Nov 15, 2024
@benbowler benbowler assigned benbowler and unassigned benbowler Nov 19, 2024
@eugene-manuilov eugene-manuilov self-assigned this Dec 3, 2024
@eugene-manuilov
Copy link
Collaborator

IB ✔

@eugene-manuilov eugene-manuilov removed their assignment Dec 3, 2024
@ivonac4 ivonac4 added the Team M Issues for Squad 2 label Dec 5, 2024
@nfmohit nfmohit self-assigned this Dec 6, 2024
@nfmohit nfmohit removed their assignment Feb 10, 2025
@techanvil techanvil self-assigned this Feb 17, 2025
@techanvil techanvil removed their assignment Feb 19, 2025
@techanvil techanvil assigned aaemnnosttv and unassigned techanvil Feb 20, 2025
@aaemnnosttv aaemnnosttv removed their assignment Feb 21, 2025
@mohitwp mohitwp self-assigned this Feb 24, 2025
@mohitwp
Copy link
Collaborator

mohitwp commented Feb 27, 2025

QA Update ✅

  • Tested on dev environment.

  • Verified that when clicking on Enable groups to set up Audience Segmentation, from either the Setup CTA on the dashboard or the Settings screen, with the Analytics edit scope not currently granted:

    -- The Analytics edit scope only  requested if it's determined that an audience or the` googlesitekit_post_type` custom 
        dimension need to be created.
    -- The OAuth flow not entered if this is not the case.
    
  • Also, verified that that the error modal still appears in unhappy path scenarios. As per QAB of Implement the unhappy paths for the Setup CTA Banner #8134

Property already have audiences

Recording.1826.mp4

Property don't have audiences

Recording.1833.mp4
Recording.1828.mp4

OAuth Error:

Recording.1830.mp4

Insufficient Permissions Error:

Recording.1831.mp4

Generic error:

Recording.1832.mp4

@mohitwp mohitwp removed their assignment Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Audiences Module: Analytics Google Analytics module related issues Needs Documentation Issues which require new or updated public-facing documentation. P1 Medium priority Team M Issues for Squad 2 Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

9 participants