feat(premium-analytics): integrate site-sync package into analytics#49267
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. |
…and-typescript-for-internal-packages' into wooa7s-1321-integrate-site-sync-package-into-analytics # Conflicts: # pnpm-lock.yaml # projects/packages/premium-analytics/package.json
…and-typescript-for-internal-packages' into wooa7s-1321-integrate-site-sync-package-into-analytics
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 is being split out separately (#49211), so the JS now composes three Jetpack-native sources.Implements WOOA7S-1321. Stacked on #49189 (WOOA7S-1320) for the internal-package tsconfig/build resolution it relies on.
Data sources (replacing the original single endpoint)
initial_full_sync_finished(milestone)JetpackScriptData.premium_analytics— page-load, no fetch (from #49211)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-syncisConnectedfieldjetpack_admin_js_script_datawoocommerce-analyticsjetpack-premium-analyticspackages/*autodiscoverylink:self-dep, matching #49221)What's intentionally not here
isConnected. Connection-gating belongs higher up (the analytics page only renders when connected).initial_full_sync_finishedis injected once and won't flip mid-session; live completion is detected from the polled analytics-module percentage reaching 100, not by re-reading script-data. Covered by tests.Notes
jest.mock, mirroringjs-packages/charts).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 uses).Does this pull request change what data or activity we track or use?
No.
Testing instructions
End-to-end (requires #49211 + a Jetpack-connected dev site): activate the plugin, open the analytics dashboard, and confirm a fresh site polls/advances, triggering advances the percentage, completion gates the dashboard open, and a stalled sync surfaces the retry error.
Optional — build-time resolution via
link:(confirms wp-build tracks the package as a module dependency once a consumer imports it):projects/packages/premium-analytics/package.jsondependencies:"@jetpack-premium-analytics/site-sync": "link:packages/site-sync"(thevalid-dependencieslint rejectslink:— relax it for the temp edit).site-syncexport inroutes/dashboard/stage.tsx.pnpm install && pnpm build→build/routes/dashboard/content.min.asset.phplists the dependency undermodule_dependencies.pnpm install.