Skip to content

POC: Move WooCommerce Analytics Sync into the shared Sync package#50715

Draft
layoutd wants to merge 10 commits into
trunkfrom
fix/shared-analytics-sync
Draft

POC: Move WooCommerce Analytics Sync into the shared Sync package#50715
layoutd wants to merge 10 commits into
trunkfrom
fix/shared-analytics-sync

Conversation

@layoutd

@layoutd layoutd commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Addresses WOOA7S-1771

Proposed changes

  • Move the existing woocommerce_analytics Sync module and its utilities from Premium Analytics into projects/packages/sync.
  • Add an opt-in WooCommerce_Analytics_Settings API so high-volume Analytics syncing remains disabled unless a consumer explicitly enables it.
  • Preserve the existing Sync module name, action names, payload shapes, checksums, options, and metadata contract.
  • Keep exactly one initialized implementation for each Sync module name, with a later legacy integration taking precedence during migration.
  • Update Premium Analytics to use the shared module while retaining its connection bootstrap, initial-sync tracking, version signal, and Bookings metadata.
  • Use the existing jetpack_sync_active_modules callable as the proposed consumer-neutral receiver capability signal instead of introducing another synced option.

This POC intentionally limits the first step to Jetpack Sync and Premium Analytics. It does not migrate Woo AI or update the WordPress.com receiver; on mixed installs, Woo AI's existing module remains authoritative so both implementations do not register the same events.

Related product discussion/links

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

No. This moves the existing WooCommerce Analytics Sync payloads into a shared package and preserves their wire contract. It does not add new tracked fields or receiver behavior.

Testing instructions

  • On a test site with WooCommerce and Premium Analytics active, inspect Automattic\Jetpack\Sync\Modules::get_modules() after plugins_loaded; confirm exactly one module reports name() === 'woocommerce_analytics' and it uses the shared Jetpack Sync class.
  • Activate Woo AI alongside Premium Analytics and repeat the inspection; confirm exactly one woocommerce_analytics module remains and Woo AI's existing implementation takes precedence.

@layoutd layoutd self-assigned this Jul 22, 2026
@github-actions

github-actions Bot commented Jul 22, 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 or WordPress.com Site Helper), and enable the fix/shared-analytics-sync branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/shared-analytics-sync
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/shared-analytics-sync

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 commented Jul 22, 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!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 22, 2026
@layoutd layoutd removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 22, 2026
@jp-launch-control

jp-launch-control Bot commented Jul 22, 2026

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/packages/sync/src/modules/class-module.php 40/258 (15.50%) -0.39% 1 ❤️‍🩹
projects/packages/sync/src/class-modules.php 22/25 (88.00%) 4.67% 0 💚
projects/packages/sync/src/modules/class-term-relationships.php 3/66 (4.55%) 1.52% -1 💚
projects/packages/premium-analytics/src/Sync/class-configuration.php 11/20 (55.00%) 24.57% -55 💚

3 files are newly checked for coverage.

File Coverage
projects/packages/sync/src/modules/class-woocommerce-analytics.php 29/448 (6.47%) 💔
projects/packages/sync/src/modules/trait-woocommerce-analytics-utilities.php 3/32 (9.38%) 💔
projects/packages/sync/src/class-woocommerce-analytics-settings.php 37/90 (41.11%) ❤️‍🩹

Full summary · PHP report · JS report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! @layoutd Took a quick look. Left two comments.

*
* Additive: appends to whatever module list is already configured rather than
* replacing it. When a legacy consumer has already contributed its own module,
* removes the shared class that Config data settings may have added earlier.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might be an ordering race here that can double-register the module on a Woo AI + PA site.

The stand-down works by checking whether a legacy module is already in the list. But ai-sync's filter also hooks at PHP_INT_MAX, and it seems that we register earlier so we keep the shared class.

Two ways out I can see: dedupe by name() in Modules::initialize_modules() , or as a stopgap, add the shared class to ai-sync's detection list before this ships.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Fixed in b3e0368 by deduplicating initialized Sync modules by name(), with later registrations winning; regression coverage exercises both orders. This keeps Woo AI’s legacy module authoritative on mixed installs.

@@ -32,14 +34,12 @@
use WC_Order_Factory;
use WC_Tax;

defined( 'ABSPATH' ) || exit;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny consistency nit: should we add a guard?

if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, restored the direct-access guard in 65a1828, and added it to the moved utility trait for consistency.

@layoutd layoutd added the Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR label Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR Docs [Package] Premium Analytics [Package] Sync [Status] In Progress [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants