feat(premium-analytics): add site-sync package into analytics#49267
feat(premium-analytics): add site-sync package into analytics#49267chihsuan wants to merge 13 commits into
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
|
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 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 If @Automattic/jetpack-vulcan want to own a shared sync-status/trigger hook in sync, I'm genuinely happy with that. |
|
Seems like a good opportunity for Can be easily done in follow-up PR btw, too. |
|
Thank you both for bringing this to our attention!
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:
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. |
5d21be9 to
10783a2
Compare
10783a2 to
0bf911c
Compare
…e-site-sync-package-into-analytics # Conflicts: # pnpm-lock.yaml # projects/packages/premium-analytics/package.json
…) 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.
…stand-in) into dashboard" This reverts commit 76be00a.
…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.
…) 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.
…) 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.
Proposed changes
Adds a
site-syncinternal package to@automattic/jetpack-premium-analyticsand configuresapiFetchauth in theinitmodule. ProvidesuseSyncStatus— 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)
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 progressGET /jetpack/v4/sync/statuspercentageprogress.woocommerce_analytics.{sent,total}POST /jetpack/v4/sync/full-syncAdaptations from
@wc-analytics/site-syncGET /wc/v3/woocommerce-analytics/sync-statusGET /jetpack/v4/sync/status+ client-side %POST .../sync-triggerPOST /jetpack/v4/sync/full-syncisConnectedfield/sync/status(#49602)woocommerce-analyticsjetpack-premium-analyticspackages/*autodiscoverylink:self-dep, matching datetime/data)What's intentionally not here
isConnected. Connection-gating belongs higher up (the analytics page only renders when connected).tests/jest.config.cjs+babel.config.cjs, landed with the data port feat(premium-analytics): port data package from next-woocommerce-analytics #49263); the hook'sjest.mockcalls work under that shared babel transform, so no custom transform is needed here.initial_full_sync_finishedis seeded from page-load script-data, then refreshed live from each/jetpack/v4/sync/statuspoll (the backend surfaces it there — stacked PR feat(premium-analytics): expose initial_full_sync_finished on sync status response #49602), so it flips mid-session without a reload. Covered by tests.Parent-level wiring (
projects/packages/premium-analytics/)The nested
packages/*are intentionally not pnpm workspace members; their runtime deps are declared on the parentpackage.jsonso the build resolves them (same model the README documents and datetime/data use). This PR adds:dependencies:@automattic/jetpack-script-data(consumed by bothinitandsite-sync).devDependencies:@testing-library/react(theuseSyncStatushook test usesrenderHook).Does this pull request change what data or activity we track or use?
No.
Testing instructions
Requires Node 24 (repo
engineStrict).Quick visual test (optional — via companion branch)
The review-only branch
wooa7s-1321-site-sync-test-harness-v2wiresuseSyncStatusinto the dashboard as a debug panel + Trigger full sync button. The realwoocommerce_analyticssync module isn't registered yet, so it points the watched module (and the backend milestone filter) atpostsfor real progress. Do not merge.On a Jetpack-connected site, open the dashboard and click Trigger full sync:
percentageclimbs0 → 100,isRunningflipstrue → false,isCompletebecomestrue, andinitialFullSyncFinishedflips0 → <timestamp>live (#49602, no reload).Screen.Recording.2026-06-15.at.1.49.38.PM.mov