Skip to content

Add setting/settings UI for including WooCommerce products in Fresh Data widgets #13625

Closed

Description

@tofumatt

Feature Description

When freshData is enabled and the WooCommerce plugin is installed/active (use the same heuristics we use elsewhere in the plugin to detect WooCommerce), we should show a new toggle/boolean setting in Analytics settings that asks the user if they want to include WooCommerce products in the "Recent Activity"/"Latest Content" cards/widgets.


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

Acceptance criteria

(All changes should require the freshData feature flag to be enabled.)

  • Add a new setting to the Analytics module settings "freshDataIncludesWooCommerceProducts". The setting should default to true.
  • When Analytics is connected and WooCommerce is connected, there should be a setting UI in Site Kit Settings > Analytics with the label Include products in Recent activity and the subtitle Show your new products alongside your latest posts in "Recent activity"
  • The Analytics datastore should have a selector (eg. shouldFreshDataIncludesWooCommerceProducts) that returns true if the "freshDataIncludesWooCommerceProducts" setting is enabled and WooCommerce is installed. If either are no longer true, the setting should return false.
  • The Settings UI should not appear when WooCommerce is disconnected.
  • Optionally: the check for WooCommerce being installed can move from the "Ads" module to the "core/site" store, given it's relevant to multiple modules. That said: the check is simple (getPluginStatusProperty( 'installed', PLUGINS.WOOCOMMERCE )) so can also be duplicated if desired.

(For context, the shouldFreshDataIncludesWooCommerceProducts() selector will control whether WooCommerce products are fetched alongside WordPress posts for "Fresh Data" cards/widgets in future issues, see #13627.)

Implementation Brief

Ownership and view-only access. The setting is a site-wide display preference, not a connection detail, so it does not go in get_owned_keys() (no ownership-change notice). It must go in get_view_only_keys(), otherwise REST_Modules_Controller strips it for view-only Dashboard Sharing users and the gate would resolve undefined on a shared dashboard.

Because the default is only registered when the flag is on, getting the setting's value returns undefined when the flag is off.

  • Update includes/Modules/Analytics_4/Settings.php:
    • Import Google\Site_Kit\Core\Util\Feature_Flags.
    • In get_default(), add 'freshDataIncludesWooCommerceProducts' => true inside a
      if ( Feature_Flags::enabled( 'freshData' ) ) block, following the rrmExpressSetup pattern in includes/Modules/Reader_Revenue_Manager/Settings.php.
    • In get_view_only_keys(), append the same key behind the same flag check.
    • In sanitize_boolean_properties(), add the key to $boolean_properties so a truthy string from the REST payload is cast to a real boolean.
  • Update assets/js/modules/analytics-4/datastore/base.js: add 'freshDataIncludesWooCommerceProducts' to settingSlugs (not ownedSettingsSlugs). This generates getFreshDataIncludesWooCommerceProducts() / setFreshDataIncludesWooCommerceProducts() and includes the key in the existing haveSettingsChanged / submitChanges flow, so the toggle saves with the settings form's "Confirm Changes" button — no bespoke save action.
  • Migrate isWooCommerceActivated from the "ads" module (
    /**
    * Determines whether the WooCommerce plugin is activated or not.
    *
    * @since 1.148.0
    *
    * @param {Object} state Data store's state.
    * @return {boolean|undefined} True if the plugin is activated, false if it is not, and undefined if data is being resolved.
    */
    isWooCommerceActivated: getPluginStatusProperty(
    'active',
    PLUGINS.WOOCOMMERCE
    ),
    ) to core/site.
  • Create assets/js/modules/analytics-4/datastore/fresh-data.ts with a single createRegistrySelector-based selector shouldIncludeWooCommerceProducts():
    • returns false immediately when ! isFeatureEnabled( 'freshData' ) (@/js/features);
    • returns undefined while any dependency is unresolved (isWooCommerceActivated(), getFreshDataIncludesWooCommerceProducts(), and isModuleConnected( MODULE_SLUG_ANALYTICS_4 ) from CORE_MODULES), so consumers can wait rather than fetch-then-refetch;
    • otherwise returns analyticsConnected && wooCommerceActive && setting === true. Register it in assets/js/modules/analytics-4/datastore/index.js's combineStores call (alphabetical, between enhancedMeasurement and keyEvents).
  • Create
    assets/js/modules/analytics-4/components/settings/SettingsIncludeWooCommerceProductsSwitch.tsx
    — a Switch plus a <p className="googlesitekit-module-settings-group__helper-text"> subtitle, modelled on assets/js/components/conversion-tracking/ConversionTrackingToggle.js. Label: Include products in Recent activity. Subtitle: Show your new products alongside your latest posts in "Recent activity". It renders null unless the freshData flag is on, isWooCommerceInstalled() is true and Analytics is connected; it is disabled while hasModuleAccess === false; it reads and writes the setting only (no direct save). One component per file — do not inline it in SettingsForm.js.
  • Update assets/js/modules/analytics-4/components/settings/SettingsForm.js to render the new component after <TrackingExclusionSwitches /> and before the EntityOwnershipChangeNotice.
  • Update assets/js/modules/analytics-4/components/settings/SettingsView.js to append { label: 'Include products in Recent activity', status: … } to the existing SettingsStatuses array, spread in only when the flag is on and WooCommerce is installed — the same conditional-spread shape already used for gtgEnabled.
  • Add stories so the new row is covered by VRT: a WithWooCommerceProductsToggle story in SettingsForm.stories.js and a matching one in SettingsView.stories.js, both with parameters = { features: [ 'freshData' ] }, a registry seeded via provideSiteInfo( registry, { wooCommerceInstalled: true, wooCommerceActive: true } ), and scenario = {}. Include an off-state story for SettingsView.

Test Coverage

  • Extend tests/phpunit/integration/Core/Assets/AssetsTest.php using its existing get_inline_base_data() helper: wooCommerceActive and wooCommerceInstalled are present and false on a site without WooCommerce, and wooCommerceActive is true when a WooCommerce class stub is defined.
  • Extend tests/phpunit/integration/Modules/Analytics_4/SettingsTest.php: with freshData enabled (the enable_feature() helper on TestCase), get() returns freshDataIncludesWooCommerceProducts => true by default, the key appears in get_view_only_keys(), and '1' / 0 sanitize to true / false; with the flag off the key is absent from both defaults and view-only keys.
  • Add assets/js/modules/analytics-4/datastore/fresh-data.test.js covering the truth table for shouldIncludeWooCommerceProducts(): false with the flag off; undefined while site info or settings are unresolved; true only when flag + Analytics connected + WooCommerce active + setting true; false when each of those is individually flipped; and specifically false when WooCommerce is installed but not active.
  • Add SettingsIncludeWooCommerceProductsSwitch.test.js: renders with the exact label and subtitle when flag + WooCommerce installed + Analytics connected; renders nothing when the flag is off, when WooCommerce is not installed, and when Analytics is not connected; still renders when WooCommerce is installed but inactive; clicking dispatches setFreshDataIncludesWooCommerceProducts and flips haveSettingsChanged() to true; the switch is disabled when hasModuleAccess is false. Use the features: [ 'freshData' ] option of the custom render from @tests/js/test-utils.
  • Extend SettingsForm.test.js to assert the row is absent by default (no flag) and present under the flag with WooCommerce installed, so the default settings-form snapshot does not shift for non-flagged sites.

QA Brief

  • With freshData off (default), open Site Kit → Settings → Analytics in both view and edit mode and confirm nothing has changed.
  • Enable freshData (tester plugin or a googlesitekit_is_feature_enabled filter snippet). Without WooCommerce installed, confirm the setting does not appear in either mode.
  • Install and activate WooCommerce, reload, and confirm the edit form shows a toggle labelled Include products in Recent activity with the subtitle Show your new products alongside your latest posts in "Recent activity", switched on by default, and that view mode lists the same label with the setting reflecting the saved value.
  • In the browser console, run googlesitekit.data.select( 'modules/analytics-4' ).shouldIncludeWooCommerceProducts() and confirm it returns true. Switch the toggle off, click Confirm Changes, reload, confirm it stayed off, and confirm the selector now returns false. Switch it back on and confirm it returns true again.
  • Deactivate WooCommerce (leaving it installed) and confirm the settings row still appears in both view and edit mode, while shouldIncludeWooCommerceProducts() returns false. Reactivate and confirm the saved preference is honoured.
  • Delete WooCommerce entirely and confirm the row disappears. Disconnect Analytics and confirm it is gone too.
  • On a shared dashboard, sign in as a view-only user and confirm shouldIncludeWooCommerceProducts() reflects the owner's saved choice. As an admin without module access, confirm the toggle is shown but disabled.
  • The Ads module now reads WooCommerce status from core/site: confirm the Ads setup flow's WooCommerce redirect modal, the Ads setup CTA banner and the "account linked via Google for WooCommerce" notification still behave as before.

Changelog entry

  • Add a setting to include WooCommerce products in the "Recent activity" tab.

Activity

  1. self-assigned this
    on Sep 18, 2026
  2. eugene-manuilov commented on Sep 18, 2026

    @eugene-manuilov
    Collaborator

    @tofumatt AC ❌

    • This setting should return true if the setting is enabled and Analytics is connected + WooCommerce is installed. If any are no longer true, the setting should return false.

    After reading this, I was confused about what it meant, but then read IB and got that you mean a selector in the Analytics datastore. Let's be clear and say which selector should be added and how it should work, instead of this abstract, confusing statement.

    • The Settings UI should not appear when WooCommerce or Analytics is disconnected.

    When Analytics is disconnected, its settings UI is not visible, so we can check just the WooCommerce plugin IMO. Also, maybe instead of hiding the setting, we should just disable it?

    • The setting should control whether WooCommerce products are fetched for "Fresh Data" cards/widgets

    This requirement is not clear. What does it mean? How should the setting control it? I believe this setting will be used in the next tickets to determine whether data should be pulled or not, but the setting itself can't control it.

    • Optionally: the check for WooCommerce being installed can move from the "Ads" module to the "core/site" store, given it's relevant to multiple modules. That said: the check is simple (getPluginStatusProperty( 'installed', PLUGINS.WOOCOMMERCE )) so can also be duplicated if desired.

    This warrants a separate ticket and is out of scope for this task.

  3. tofumatt commented on Sep 22, 2026

    @tofumatt
    CollaboratorAuthor

    After reading this, I was confused about what it meant, but then read IB and got that you mean a selector in the Analytics datastore. Let's be clear and say which selector should be added and how it should work, instead of this abstract, confusing statement.

    Agreed that it was vague, so I've clarified what I meant there, thanks 👍🏻

    When Analytics is disconnected, its settings UI is not visible, so we can check just the WooCommerce plugin IMO. Also, maybe instead of hiding the setting, we should just disable it?

    I've simplified that (and in a few other places too), good call. But I think it's best not to show the setting at all for users without Woo instead of disabling it; most users aren't Woo users so it's just visual noise/confusing for the majority of users.

    This requirement is not clear. What does it mean? How should the setting control it? I believe this setting will be used in the next tickets to determine whether data should be pulled or not, but the setting itself can't control it.

    I've clarified it; that sentence was for extra context but I've moved it and not made it an AC point.

    This warrants a separate ticket and is out of scope for this task.

    The exact logic we want to use is in that selector already, and if we don't extract it we'll need to duplicate the logic as part of this ticket, then file another to refactor. Might as well just do it as part of this ticket now that the logic is used across two modules.

  4. 7 remaining items

  5. self-assigned this
    on Sep 25, 2026
  6. removed their assignment
    on Sep 30, 2026
  7. self-assigned this
    on Oct 5, 2026
  8. mohitwp commented on Oct 6, 2026

    @mohitwp
    Collaborator

    QA Update ⚠️

    @mehidi258

    Quick clarification: the AC seems to suggest the “Include products in Recent activity” setting should not be available when WooCommerce is disconnected, while the IB/QAB expect the setting to remain visible when WooCommerce is installed but deactivated, with shouldIncludeWooCommerceProducts() returning false.
    I’ve tested against the IB/QAB behavior. Can you confirm that this is the intended behavior?

    Verified the new “Include products in Recent activity” Analytics setting with the freshData feature flag enabled, including the relevant visibility, persistence, selector, permissions, and WooCommerce states.

    • Confirmed the setting is not shown when freshData is disabled.
    • Confirmed the setting is not shown when WooCommerce is not installed.
    • With WooCommerce installed and active, verified the setting appears in both Analytics view and edit modes with the expected label/description and is enabled by default.
    • Verified the saved preference persists when toggled OFF/ON.
    • Confirmed shouldIncludeWooCommerceProducts() returns the expected value based on the saved setting and WooCommerce/Analytics state.
    • Verified the setting remains visible when WooCommerce is installed but deactivated, while the selector returns false.
    • Verified the setting is hidden when WooCommerce is removed.
    • Verified with Analytics disconnected that the selector returns false.
    • Verified for a user without Analytics module access that the setting remains visible but the toggle is disabled.
    • Verified the shared/view-only behavior with the saved setting available as expected.

    Ads / WooCommerce regression checks also passed:

    • With WooCommerce active and Google for WooCommerce inactive, the WooCommerce Ads modal was displayed with both expected options, and selecting “Use Google for WooCommerce” opened the plugin installation page in a new tab.
    • With Google for WooCommerce active, selecting “Use Google for WooCommerce” opened the GfW setup page in a new tab as expected.
    • With a gla_ads_id present, Site Kit correctly detected the existing Ads account and displayed the expected “We’ve detected an existing Ads account via the Google for WooCommerce plugin” notice with Create new account and Keep existing account actions.
    • Selecting Keep existing account dismissed the notice as expected without automatically connecting the Site Kit Ads module.
    Details

    Toggle ON

    Image

    Toggle OFF

    Image

    Toggle ON again

    Image

    WooCommerce Installed but deactive

    Image Image Image

    WooCommerce Active

    Image

    Analytics disconnected and WooCommerce installed

    Image

    view only dashboard - toggle on

    Image

    view only dashboard - toggle OFF

    Image

    Admin without analytics access

    Image

    Ads module Regression

    Recording.3480.mp4
    Recording.3481.mp4
    Recording.3482.mp4
  9. mehidi258 commented on Oct 7, 2026

    @mehidi258
    Collaborator

    @mohitwp thanks for the thorough QA!

    Yes, the behaviour you tested against the IB/QAB is the intended one. In the AC, "WooCommerce is connected/disconnected" means installed vs. not installed, which is the same check the selector and "Optionally" bullets use. The IB made this concrete and was approved:

    • The settings row is hidden only when WooCommerce is not installed. The aim (per this comment) is to keep it from being noise on sites that don't use WooCommerce. A site with WooCommerce installed but deactivated still uses it, so the row stays visible and the saved preference applies again once WooCommerce is reactivated.
    • shouldIncludeWooCommerceProducts() also requires WooCommerce to be active, so it returns false while WooCommerce is deactivated. Products can't be fetched in that state, so the selector is what actually controls fetching in Add the "recent posts and products" datastore fetch #13627.

    So "visible when installed but deactivated, selector returns false" is correct. All the other checks you listed match the expected behaviour too.

  10. removed their assignment
    on Oct 7, 2026
  11. mohitwp commented on Oct 8, 2026

    @mohitwp
    Collaborator

    QA Update ✅

    Verified the new “Include products in Recent activity” Analytics setting with the freshData feature flag enabled, including the relevant visibility, persistence, selector, permissions, and WooCommerce states.

    • Confirmed the setting is not shown when freshData is disabled.
    • Confirmed the setting is not shown when WooCommerce is not installed.
    • With WooCommerce installed and active, verified the setting appears in both Analytics view and edit modes with the expected label/description and is enabled by default.
    • Verified the saved preference persists when toggled OFF/ON.
    • Confirmed shouldIncludeWooCommerceProducts() returns the expected value based on the saved setting and WooCommerce/Analytics state.
    • Verified the setting remains visible when WooCommerce is installed but deactivated, while the selector returns false.
    • Verified the setting is hidden when WooCommerce is removed.
    • Verified with Analytics disconnected that the selector returns false.
    • Verified for a user without Analytics module access that the setting remains visible but the toggle is disabled.
    • Verified the shared/view-only behavior with the saved setting available as expected.

    Ads / WooCommerce regression checks also passed:

    • With WooCommerce active and Google for WooCommerce inactive, the WooCommerce Ads modal was displayed with both expected options, and selecting “Use Google for WooCommerce” opened the plugin installation page in a new tab.
    • With Google for WooCommerce active, selecting “Use Google for WooCommerce” opened the GfW setup page in a new tab as expected.
    • With a gla_ads_id present, Site Kit correctly detected the existing Ads account and displayed the expected “We’ve detected an existing Ads account via the Google for WooCommerce plugin” notice with Create new account and Keep existing account actions.
    • Selecting Keep existing account dismissed the notice as expected without automatically connecting the Site Kit Ads module.
    Details

    Toggle ON

    Image

    Toggle OFF

    Image

    Toggle ON again

    Image

    WooCommerce Installed but deactive

    Image Image Image

    WooCommerce Active

    Image

    Analytics disconnected and WooCommerce installed

    Image

    view only dashboard - toggle on

    Image

    view only dashboard - toggle OFF

    Image

    Admin without analytics access

    Image

    Ads module Regression

    Recording.3480.mp4
    Recording.3481.mp4
    Recording.3482.mp4
  12. removed their assignment
    on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0High priorityTeam SIssues for Squad 1Type: EnhancementImprovement of an existing feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions