Skip to content

Premium Analytics: Refresh the stored connection slug when the dashboard turns on or off - #53779

Closed
louwie17 wants to merge 1 commit into
trunkfrom
fix-premium-analytics-connection-slug-refresh
Closed

louwie17 wants to merge 1 commit into
trunkfrom
fix-premium-analytics-connection-slug-refresh

Conversation

@louwie17

Copy link
Copy Markdown
Contributor

Proposed changes

WordPress.com only processes WooCommerce Analytics data for a site (the wc_product_lookup rows built from synced products, custom-table hooks, and the rest) when the site's synced jetpack_connection_active_plugins option lists jetpack-premium-analytics, woocommerce-analytics or woocommerce-ai. Premium Analytics registers its slug at runtime through Config::ensure( 'connection', … ). The Connection package only rewrites the stored option after a plugin is activated or deactivated: update_option_active_plugins sets the jetpack_connection_active_plugins_refresh transient, and the next POST request consumes it. Turning Premium Analytics on inside Jetpack is an option change, so the slug never reached the stored option. On a store without another qualifying plugin, WordPress.com then skipped product rows: products report rows had null name, SKU and type, and type-filtered widgets such as Top performing products stayed empty.

This PR changes only the Premium Analytics package. It uses the Connection package's existing public Plugin_Storage::set_flag_to_refresh_active_connected_plugins(), guarded with method_exists().

  • Connection_Configuration::configure(), which runs whenever the dashboard is on, now checks whether the stored option lacks the Premium Analytics slug and, if so, sets the refresh flag. The Connection package then rewrites the option on the next POST. This covers every way of enabling the dashboard, including the option, the jetpack_premium_analytics_enabled filter and the blog sticker, as well as sites that enabled it before this fix. Once the option is correct, the check costs one autoloaded get_option() per request. While the option is stale and no POST has arrived yet, it skips the write if the flag is already set.
  • Enablement_Setting also sets the flag when the opt-in option is added or changed. This is the disable direction: once the dashboard is off, the package no longer boots, so nothing else would drop the slug.

Known gap: if the dashboard is turned off by any route other than the settings write, the slug stays in the stored option until the next plugin activation or deactivation. Those routes are the filter, the blog sticker, removing the Stats module, or wp option update from WP-CLI. The only effect is that WordPress.com keeps processing WooCommerce Analytics data for that site. Closing the gap would mean hooking into Jetpack's disabled branch, which I left out of this PR.

The standalone plugins/premium-analytics is not affected. It always calls Analytics::init(), so activating it already triggers the refresh. For that reason it gets no changelog entry.

Lookup data and catalog backfill (#53728) depend on this fix.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No. It changes when an existing synced option is refreshed, so WordPress.com processes the WooCommerce Analytics data this site already opted into through Premium Analytics.

Testing instructions

Unit tests: jp test php packages/premium-analytics.

On a Jurassic Ninja store with WooCommerce, Jetpack (built from this branch) and WC Smooth Generator, connected, with the Stats module active:

  1. Before enabling, run wp option get jetpack_connection_active_plugins. It should not list jetpack-premium-analytics.
  2. Run wp option update jetpack_premium_analytics_enabled 1. Do not activate or deactivate any plugin.
  3. Make one POST request, for example any wp-admin action that hits admin-ajax.php, or curl -X POST https://<site>/wp-admin/admin-ajax.php.
  4. Run wp option get jetpack_connection_active_plugins again. It now lists jetpack-premium-analytics.
  5. Create a product and place an order for it. WordPress.com's products report (wpcom/v2/sites/<blog_id>/analytics/reports/products, date_type=created) shows its name, SKU and type.
  6. Turn the dashboard off through the UI (Stats v2 › switch off), make another POST, and confirm the slug is gone from the option.
  7. Check that wp-content/debug.log has no new notices.

🤖 Generated with Claude Code

…ard turns on or off

WordPress.com only processes WooCommerce Analytics data for a site whose synced
jetpack_connection_active_plugins lists jetpack-premium-analytics. Enabling the
dashboard inside Jetpack is an option change, not a plugin activation, so the
Connection package never rewrote that option.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix-premium-analytics-connection-slug-refresh branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix-premium-analytics-connection-slug-refresh

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions Bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests labels Oct 19, 2026
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/src/class-connection-configuration.php 14/15 (93.33%) -6.67% 1 ❤️‍🩹
projects/packages/premium-analytics/src/class-enablement-setting.php 26/27 (96.30%) 0.30% 0 💚

Full summary · PHP report · JS report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Premium Analytics [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests [Type] Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant