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

Integrate First-Party Mode Toggle into Analytics Settings Form #9654

Closed
2 tasks done
hussain-t opened this issue Nov 11, 2024 · 8 comments
Closed
2 tasks done

Integrate First-Party Mode Toggle into Analytics Settings Form #9654

hussain-t opened this issue Nov 11, 2024 · 8 comments
Labels
P0 High priority Team M Issues for Squad 2 Type: Enhancement Improvement of an existing feature

Comments

@hussain-t
Copy link
Collaborator

hussain-t commented Nov 11, 2024

Feature Description

Add the <FirstPartyModeToggle /> component to the Analytics settings forms, enabling existing users to opt into First-party mode. The toggle will default to "off" and can be enabled if desired.

If either the FPFE health check or script access check fails, the toggle will be disabled and grayed out, displaying an error message instructing users that additional server configuration is needed to enable First-Party Mode.

For details, refer to the Design Doc.


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

Acceptance criteria

Implementation Brief

  • Update assets/js/modules/analytics-4/components/settings/SettingsForm.js, import and render the new FirstPartyModeToggle if the firstPartyMode feature flag is enabled.
  • Update assets/js/modules/analytics-4/datastore/settings.js:
    • Within the saveSettings function, check if the first party mode settings has changed using the haveFirstPartyModeSettingsChanged selector, if so dispatch saveFirstPartyModeSettings, returning an error if there is one, similar to how the conversion tracking setting is saved:
      const haveConversionTrackingSettingsChanged =
      select( CORE_SITE ).haveConversionTrackingSettingsChanged();
      if ( haveConversionTrackingSettingsChanged ) {
      const { error } = await dispatch(
      CORE_SITE
      ).saveConversionTrackingSettings();
      if ( error ) {
      return { error };
      }
      }
    • Within the rollbackChanges function, within the haveSettingsChanged check block, dispatch the action resetFirstPartyModeSettings.
      dispatch( CORE_SITE ).resetConversionTrackingSettings();

Test Coverage

  • Add new tests in assets/js/modules/analytics-4/datastore/settings.test.js to confirm the first-party mode setting is saved and rolled back.

QA Brief

  1. Activate Site Kit with the firstPartyMode feature flag enabled and ensure that the Analytics module is active and connected.
  2. Navigate to Site Kit > Settings > Analytics and click the Edit link. Verify that the First-party mode toggle is displayed.
  3. Change the toggle state:
    • Confirm that the submit button text changes from Save to Confirm changes.
  4. Save the changes:
    • Verify that the new toggle state is persisted after saving.
    • Refresh the settings page to ensure the toggle retains its updated state.
  5. Cancel changes:
    • Change the toggle state and click Cancel.
    • Verify that the toggle reverts to its previous state when reopening the settings edit screen by clicking the Edit link.

Note: If your test site fails either of the health checks, you can force local settings to test the toggle functionality using the following action in the console:

googlesitekit.data.dispatch( 'core/site' )
    .receiveGetFirstPartyModeSettings( {
        isEnabled: true,
        isFPMHealthy: true,
        isScriptAccessEnabled: true,
    } );

Changelog entry

  • Integrate the First-party mode toggle into the Analytics module’s settings form, allowing users to enable or disable First-party mode.
@hussain-t hussain-t added Type: Enhancement Improvement of an existing feature Team M Issues for Squad 2 P0 High priority labels Nov 11, 2024
@hussain-t hussain-t assigned hussain-t and unassigned hussain-t Nov 19, 2024
@techanvil techanvil self-assigned this Nov 20, 2024
@techanvil
Copy link
Collaborator

techanvil commented Nov 20, 2024

Hey @hussain-t, this comment applies to these AC too: #9655 (comment).

Update: see also #9655 (comment).

@techanvil techanvil assigned hussain-t and unassigned techanvil Nov 20, 2024
@hussain-t
Copy link
Collaborator Author

Thanks, @techanvil. I've removed specifying the component name, back to you.

@hussain-t hussain-t assigned techanvil and unassigned hussain-t Nov 20, 2024
@techanvil
Copy link
Collaborator

Thanks @hussain-t!

AC ✅

@techanvil techanvil removed their assignment Nov 20, 2024
@benbowler benbowler self-assigned this Nov 25, 2024
@benbowler
Copy link
Collaborator

@hussain-t I've picked this up for IB as I'm back in squad M next week. Working through this however, I found an issue with rolling back the settings if the user cancels changes in the settings form. Because FPM uses a fetch store instead of a settings store, it doesn't implement rollback and we don't know if the user changed the setting or not.

What do you think about switching the FPM store for the isEnabled setting to be a settings store rather than a fetch store? Do you see issues with this?

const fetchGetFirstPartyModeSettingsStore = createFetchStore( {
baseName: 'getFirstPartyModeSettings',
controlCallback: () =>
API.get( 'core', 'site', 'fpm-settings', undefined, {
useCache: false,
} ),
reducerCallback: settingsReducerCallback,
} );

@hussain-t
Copy link
Collaborator Author

hussain-t commented Nov 26, 2024

Hi @benbowler, the reset and rollback changes are being implemented in #9688. Let me know if that helps. Thanks!

Update: It should work similarly to the conversion tracking settings.

@hussain-t
Copy link
Collaborator Author

Update assets/js/components/settings/SettingsActiveModule/Footer.js, after the following line, check if slug is either analytics-4 or ads, if so dispatch the saveFirstPartyModeSettings action to save the FPM setting.

@benbowler, we should call the saveFirstPartyModeSettings action within the Analytics saveSettings similar to the conversion tracking saveConversionTrackingSettings.

@benbowler benbowler removed their assignment Nov 27, 2024
@techanvil techanvil self-assigned this Nov 28, 2024
@techanvil
Copy link
Collaborator

IB ✅

@techanvil techanvil removed their assignment Dec 5, 2024
@hussain-t hussain-t assigned techanvil and unassigned hussain-t Dec 5, 2024
techanvil added a commit that referenced this issue Dec 5, 2024
…toggle-analytics

Enhancement/#9654 - Integrate First-Party Mode Toggle into Analytics Settings
@techanvil techanvil removed their assignment Dec 5, 2024
@wpdarren wpdarren self-assigned this Dec 6, 2024
@wpdarren
Copy link
Collaborator

wpdarren commented Dec 6, 2024

QA Update: ✅

Verified:

  • The First-Party Mode Toggle component is integrated into the Analytics module’s settings form.
    • The toggle allows users to enable or disable First-party mode.
    • The toggle is default to off for existing users.
    • If either the FPFE health check or script access check fails, the toggle is disabled and a notification appears.
    • Changes made to the toggle state (on/off) are saved on the First-party mode settings in the datastore and persist them on the server.
    • If the toggle is enabled via the settings form, the First-party mode setup banner is dismissed.
  • The component’s styling and placement align with the specifications in the Figma design.
Screenshots

Image
Image
Image
Image

@wpdarren wpdarren removed their assignment Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 High priority Team M Issues for Squad 2 Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

5 participants