Skip to content

feat(premium-analytics): add site-sync package into analytics#49267

Open
chihsuan wants to merge 13 commits into
wooa7s-1542-expose-sync-milestone-livefrom
wooa7s-1321-integrate-site-sync-package-into-analytics
Open

feat(premium-analytics): add site-sync package into analytics#49267
chihsuan wants to merge 13 commits into
wooa7s-1542-expose-sync-milestone-livefrom
wooa7s-1321-integrate-site-sync-package-into-analytics

Conversation

@chihsuan

@chihsuan chihsuan commented May 29, 2026

Copy link
Copy Markdown
Member

Proposed changes

Adds a site-sync internal package to @automattic/jetpack-premium-analytics and configures apiFetch auth in the init module. Provides useSyncStatus — a React hook that polls Jetpack's native sync endpoints, exposes analytics-scoped progress, completion gating, and stall detection for the analytics dashboard.

This is a redesign, not a straight port of WooCommerce-Analytics' @wc-analytics/site-sync. The original hit a single custom WooCommerce REST endpoint; that PHP was split out separately (#49211, now merged), so the JS composes three Jetpack-native sources.

Data sources (replacing the original single endpoint)

Field Source
initial_full_sync_finished (milestone) JetpackScriptData.premium_analytics.initial_full_sync_finished (int) — page-load seed, refreshed live from /sync/status (#49602)
started / finished / per-module progress poll GET /jetpack/v4/sync/status
analytics percentage computed client-side from progress.woocommerce_analytics.{sent,total}
trigger POST /jetpack/v4/sync/full-sync

Adaptations from @wc-analytics/site-sync

Original Here Why
GET /wc/v3/woocommerce-analytics/sync-status GET /jetpack/v4/sync/status + client-side % Custom WC endpoint not ported; consume Jetpack core directly
POST .../sync-trigger POST /jetpack/v4/sync/full-sync No duplicate trigger endpoint (per backend WOOA7S-1436)
isConnected field dropped Pure passthrough — nothing branched on it; avoids a connection dep
milestone re-read every poll seeded from script-data, refreshed live from the poll Backend persists it; injected via script-data and surfaced on /sync/status (#49602)
text domain woocommerce-analytics jetpack-premium-analytics Monorepo convention
symlink build hack wp-build packages/* autodiscovery Internal-package convention (no link: self-dep, matching datetime/data)

What's intentionally not here

Parent-level wiring (projects/packages/premium-analytics/)

The nested packages/* are intentionally not pnpm workspace members; their runtime deps are declared on the parent package.json so the build resolves them (same model the README documents and datetime/data use). This PR adds:

  • dependencies: @automattic/jetpack-script-data (consumed by both init and site-sync).
  • devDependencies: @testing-library/react (the useSyncStatus hook test uses renderHook).

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

No.

Testing instructions

Requires Node 24 (repo engineStrict).

pnpm install
cd projects/packages/premium-analytics
pnpm test         # jest — 121 tests pass (incl. site-sync status helpers + useSyncStatus hook)
pnpm typecheck    # tsgo --noEmit — passes
pnpm exec eslint . # clean
pnpm build        # wp-build — passes

Quick visual test (optional — via companion branch)

The review-only branch wooa7s-1321-site-sync-test-harness-v2 wires useSyncStatus into the dashboard as a debug panel + Trigger full sync button. The real woocommerce_analytics sync module isn't registered yet, so it points the watched module (and the backend milestone filter) at posts for real progress. Do not merge.

git fetch origin wooa7s-1321-site-sync-test-harness-v2 && git checkout wooa7s-1321-site-sync-test-harness-v2
pnpm install && cd projects/packages/premium-analytics && pnpm build
wp post generate --count=1500

On a Jetpack-connected site, open the dashboard and click Trigger full sync: percentage climbs 0 → 100, isRunning flips true → false, isComplete becomes true, and initialFullSyncFinished flips 0 → <timestamp> live (#49602, no reload).

Screen.Recording.2026-06-15.at.1.49.38.PM.mov

Note: the @jetpack-premium-analytics/site-sync specifier is a temporary bridge inherited from the source repo. Once name-based identity (WordPress/gutenberg#78822, mirrored monorepo-wide by #48089) lands, the specifier becomes the package's own name (@automattic/jetpack-premium-analytics-site-sync) and the bare-scope alias/link: drop out — so long term there's no @jetpack-premium-analytics/... to maintain. The package's canonical name is @automattic/jetpack-premium-analytics-site-sync.

@github-actions

github-actions Bot commented May 29, 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 wooa7s-1321-integrate-site-sync-package-into-analytics branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack wooa7s-1321-integrate-site-sync-package-into-analytics
bin/jetpack-downloader test jetpack-mu-wpcom-plugin wooa7s-1321-integrate-site-sync-package-into-analytics

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 May 29, 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 May 29, 2026
@chihsuan chihsuan self-assigned this May 29, 2026
@chihsuan chihsuan marked this pull request as draft May 29, 2026 06:50
@simison

simison commented May 29, 2026

Copy link
Copy Markdown
Member

Would it make sense to rather have this be as part of the sync module as a feature? cc @Automattic/jetpack-vulcan who maintain sync.

@chihsuan

Copy link
Copy Markdown
Member Author

Would it make sense to rather have this be as part of the sync module as a feature? cc @Automattic/jetpack-vulcan who maintain sync.

Good call-out, thanks! I The way I see it, the package/hook is really doing two things: the generic part (polling /sync/status, kicking off a full sync, the polling loop + stall detection) and the analytics-specific part (scoping progress to the woocommerce_analytics module and reading the premium_analytics milestone from script-data).

The analytics-specific stuff pretty clearly belongs here. The generic part is the interesting question. It'd be reusable, so sync could be a natural home. The only snag is that packages/sync is PHP-only right now, so we'd be standing up a brand-new JS layer there just for this one consumer.

If @Automattic/jetpack-vulcan want to own a shared sync-status/trigger hook in sync, I'm genuinely happy with that.

@simison

simison commented May 29, 2026

Copy link
Copy Markdown
Member

Seems like a good opportunity for projects/js-packages/sync then for generic parts but really up to Vulcan team.

Can be easily done in follow-up PR btw, too.

@fgiannar

Copy link
Copy Markdown
Contributor

Thank you both for bringing this to our attention!

If @Automattic/jetpack-vulcan want to own a shared sync-status/trigger hook in sync, I'm genuinely happy with that.

For now we don't plan to add a JS layer in the sync package, however this could indeed be implemented as part of the following two potential future projects:

  • pf5801-1If-p2
  • pghT6q-9Z-p2

Actually, when we were brainstorming on the first one we did mention that we could potentially "steal" parts of your implementation, since you are the only plugin that exposes a Sync related UI. For now, feel free to proceed with this approach and we can refactor in the future as needed, ideally without duplicating the effort.

@jp-launch-control

jp-launch-control Bot commented Jun 2, 2026

Copy link
Copy Markdown

Code Coverage Summary

No summary data is available for parent commit 687ee13, so cannot calculate coverage changes. 😴

If that commit is a feature branch rather than a trunk commit, this is expected. Otherwise, this should be updated once coverage for 687ee13 is available.

Full summary · PHP report · JS report

Base automatically changed from wooa7s-1320-configure-workspace-and-typescript-for-internal-packages to trunk June 5, 2026 02:37
@chihsuan chihsuan force-pushed the wooa7s-1321-integrate-site-sync-package-into-analytics branch 2 times, most recently from 5d21be9 to 10783a2 Compare June 10, 2026 07:04
@chihsuan chihsuan marked this pull request as ready for review June 10, 2026 07:12
@chihsuan chihsuan force-pushed the wooa7s-1321-integrate-site-sync-package-into-analytics branch from 10783a2 to 0bf911c Compare June 10, 2026 07:28
@chihsuan chihsuan requested review from a team, kangzj, louwie17 and retrofox June 10, 2026 08:01
…e-site-sync-package-into-analytics

# Conflicts:
#	pnpm-lock.yaml
#	projects/packages/premium-analytics/package.json
@chihsuan chihsuan changed the base branch from trunk to wooa7s-1542-expose-sync-milestone-live June 15, 2026 05:06
…) into dashboard

DO NOT MERGE. Testing-only branch for PR #49267. Wires useSyncStatus into the dashboard route (debug panel + trigger). The real woocommerce_analytics sync module is not registered yet, so points ANALYTICS_SYNC_MODULE and the jetpack_premium_analytics_sync_modules milestone filter at posts so reviewers can exercise the flow. Adds a temporary link: dep on site-sync.
chihsuan added 4 commits June 15, 2026 13:36
…ad of stopping

A single failed /sync/status fetch tore down polling permanently; recovery
required a full-sync re-trigger. Keep polling through transient errors and
only give up after MAX_POLL_FAILURES consecutive failures. Add tests for
continued polling, unmount cleanup, triggerSync resume, and error self-heal.
…egistration

init() registered root-URL/nonce middleware onto the shared apiFetch chain on
every call. Latch behind a module flag so re-mounts or a second boot don't
stack duplicates; only latch once registration actually happened.
chihsuan added a commit that referenced this pull request Jun 15, 2026
…) into dashboard

DO NOT MERGE. Testing-only branch for PR #49267. Wires useSyncStatus into the dashboard route (debug panel + trigger). The real woocommerce_analytics sync module is not registered yet, so points ANALYTICS_SYNC_MODULE and the jetpack_premium_analytics_sync_modules milestone filter at posts so reviewers can exercise the flow. Adds a temporary link: dep on site-sync.
chihsuan added a commit that referenced this pull request Jun 15, 2026
…) into dashboard

DO NOT MERGE. Testing-only branch for PR #49267. Wires useSyncStatus into the dashboard route (debug panel + trigger). The real woocommerce_analytics sync module is not registered yet, so points ANALYTICS_SYNC_MODULE and the jetpack_premium_analytics_sync_modules milestone filter at posts so reviewers can exercise the flow. Adds a temporary link: dep on site-sync.
@chihsuan chihsuan added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Jun 15, 2026
@chihsuan chihsuan changed the title feat(premium-analytics): integrate site-sync package into analytics feat(premium-analytics): add site-sync package into analytics Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants