Repository navigation
Add setting/settings UI for including WooCommerce products in Fresh Data widgets #13625
Description
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 totrue. - 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 returnstrueif the"freshDataIncludesWooCommerceProducts"setting is enabled and WooCommerce is installed. If either are no longer true, the setting should returnfalse. - 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' => trueinside a
if ( Feature_Flags::enabled( 'freshData' ) )block, following therrmExpressSetuppattern inincludes/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_propertiesso a truthy string from the REST payload is cast to a real boolean.
- Import
- Update
assets/js/modules/analytics-4/datastore/base.js: add'freshDataIncludesWooCommerceProducts'tosettingSlugs(notownedSettingsSlugs). This generatesgetFreshDataIncludesWooCommerceProducts()/setFreshDataIncludesWooCommerceProducts()and includes the key in the existinghaveSettingsChanged/submitChangesflow, so the toggle saves with the settings form's "Confirm Changes" button — no bespoke save action. - Migrate
isWooCommerceActivatedfrom the "ads" module () tosite-kit-wp/assets/js/modules/ads/datastore/module-data.js
Lines 178 to 189 in 4984509
/** * 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 ), core/site. - Create
assets/js/modules/analytics-4/datastore/fresh-data.tswith a singlecreateRegistrySelector-based selectorshouldIncludeWooCommerceProducts():- returns
falseimmediately when! isFeatureEnabled( 'freshData' )(@/js/features); - returns
undefinedwhile any dependency is unresolved (isWooCommerceActivated(),getFreshDataIncludesWooCommerceProducts(), andisModuleConnected( MODULE_SLUG_ANALYTICS_4 )fromCORE_MODULES), so consumers can wait rather than fetch-then-refetch; - otherwise returns
analyticsConnected && wooCommerceActive && setting === true. Register it inassets/js/modules/analytics-4/datastore/index.js'scombineStorescall (alphabetical, betweenenhancedMeasurementandkeyEvents).
- returns
- Create
assets/js/modules/analytics-4/components/settings/SettingsIncludeWooCommerceProductsSwitch.tsx
— aSwitchplus a<p className="googlesitekit-module-settings-group__helper-text">subtitle, modelled onassets/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 rendersnullunless thefreshDataflag is on,isWooCommerceInstalled()istrueand Analytics is connected; it isdisabledwhilehasModuleAccess === false; it reads and writes the setting only (no direct save). One component per file — do not inline it inSettingsForm.js. - Update
assets/js/modules/analytics-4/components/settings/SettingsForm.jsto render the new component after<TrackingExclusionSwitches />and before theEntityOwnershipChangeNotice. - Update
assets/js/modules/analytics-4/components/settings/SettingsView.jsto append{ label: 'Include products in Recent activity', status: … }to the existingSettingsStatusesarray, spread in only when the flag is on and WooCommerce is installed — the same conditional-spread shape already used forgtgEnabled. - Add stories so the new row is covered by VRT: a
WithWooCommerceProductsTogglestory inSettingsForm.stories.jsand a matching one inSettingsView.stories.js, both withparameters = { features: [ 'freshData' ] }, a registry seeded viaprovideSiteInfo( registry, { wooCommerceInstalled: true, wooCommerceActive: true } ), andscenario = {}. Include an off-state story forSettingsView.
Test Coverage
- Extend
tests/phpunit/integration/Core/Assets/AssetsTest.phpusing its existingget_inline_base_data()helper:wooCommerceActiveandwooCommerceInstalledare present andfalseon a site without WooCommerce, andwooCommerceActiveistruewhen aWooCommerceclass stub is defined. - Extend
tests/phpunit/integration/Modules/Analytics_4/SettingsTest.php: withfreshDataenabled (theenable_feature()helper onTestCase),get()returnsfreshDataIncludesWooCommerceProducts => trueby default, the key appears inget_view_only_keys(), and'1'/0sanitize totrue/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.jscovering the truth table forshouldIncludeWooCommerceProducts():falsewith the flag off;undefinedwhile site info or settings are unresolved;trueonly when flag + Analytics connected + WooCommerce active + settingtrue;falsewhen each of those is individually flipped; and specificallyfalsewhen 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 dispatchessetFreshDataIncludesWooCommerceProductsand flipshaveSettingsChanged()totrue; the switch is disabled whenhasModuleAccessisfalse. Use thefeatures: [ 'freshData' ]option of the customrenderfrom@tests/js/test-utils. - Extend
SettingsForm.test.jsto 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
freshDataoff (default), open Site Kit → Settings → Analytics in both view and edit mode and confirm nothing has changed. - Enable
freshData(tester plugin or agooglesitekit_is_feature_enabledfilter 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 returnstrue. Switch the toggle off, click Confirm Changes, reload, confirm it stayed off, and confirm the selector now returnsfalse. Switch it back on and confirm it returnstrueagain. - Deactivate WooCommerce (leaving it installed) and confirm the settings row still appears in both view and edit mode, while
shouldIncludeWooCommerceProducts()returnsfalse. 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
freshDatafeature flag #13621eugene-manuilov commentedon Sep 18, 2026
@tofumatt AC ❌
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.
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?
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.
This warrants a separate ticket and is out of scope for this task.
tofumatt commentedon Sep 22, 2026
Agreed that it was vague, so I've clarified what I meant there, thanks 👍🏻
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.
I've clarified it; that sentence was for extra context but I've moved it and not made it an AC point.
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.
7 remaining items
mohitwp commentedon Oct 6, 2026
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.
Ads / WooCommerce regression checks also passed:
Details
Toggle ON
Toggle OFF
Toggle ON again
WooCommerce Installed but deactive
WooCommerce Active
Analytics disconnected and WooCommerce installed
view only dashboard - toggle on
view only dashboard - toggle OFF
Admin without analytics access
Ads module Regression
Recording.3480.mp4
Recording.3481.mp4
Recording.3482.mp4
mehidi258 commentedon Oct 7, 2026
@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:
shouldIncludeWooCommerceProducts()also requires WooCommerce to be active, so it returnsfalsewhile 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.mohitwp commentedon Oct 8, 2026
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.
Ads / WooCommerce regression checks also passed:
Details
Toggle ON
Toggle OFF
Toggle ON again
WooCommerce Installed but deactive
WooCommerce Active
Analytics disconnected and WooCommerce installed
view only dashboard - toggle on
view only dashboard - toggle OFF
Admin without analytics access
Ads module Regression
Recording.3480.mp4
Recording.3481.mp4
Recording.3482.mp4