RTC: add jetpack_rtc_blocked Tracks event#49579
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! |
Code Coverage SummaryCoverage changed in 1 file.
|
There was a problem hiding this comment.
Pull request overview
Adds RTC telemetry for cases where a user is turned away due to the per-room contributor cap, and makes RTC Tracks events consistently include post/user context by sourcing it from the server-injected notices config.
Changes:
- Add
jetpack_rtc_blockedTracks event and hook it into the room-limit overflow path. - Refactor awareness roster helpers into
tracking/awareness.tsand reuse them across join/blocked tracking. - Add unit tests for
room-limit.tsand the new tracking modules; remove unused@wordpress/datadependency.
Reviewed changes
Copilot reviewed 14 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| projects/packages/rtc/src/js/tracking/tracks.ts | Stop reading editor-store context; use window.jetpackRtcNotices for common event context. |
| projects/packages/rtc/src/js/tracking/track-join.ts | Use shared awareness helpers; skip join snapshot if the room-limit breach occurred during settle delay. |
| projects/packages/rtc/src/js/tracking/track-blocked.ts | New blocked-event recorder emitting roster and role flags. |
| projects/packages/rtc/src/js/tracking/awareness.ts | New shared awareness helpers (getContributorIds, getLocalUserId). |
| projects/packages/rtc/src/js/tracking/test/tracks.test.ts | Update tests for server-config-sourced post/user context. |
| projects/packages/rtc/src/js/tracking/test/track-join.test.ts | Update join tests and add coverage for “breached during delay” case. |
| projects/packages/rtc/src/js/tracking/test/track-blocked.test.ts | New tests for blocked tracking payload. |
| projects/packages/rtc/src/js/tracking/test/awareness.test.ts | New tests for awareness helper module. |
| projects/packages/rtc/src/js/notices/test/room-limit.test.ts | New tests asserting blocked tracking fires only for overflow (local) client. |
| projects/packages/rtc/src/js/notices/room-limit.ts | Emit blocked event when local client is in overflow, before teardown. |
| projects/packages/rtc/src/js/notices/images.d.ts | Extend notices config typings with postType/userId. |
| projects/packages/rtc/src/class-rtc.php | Inject postType and userId into jetpackRtcNotices inline config. |
| projects/packages/rtc/package.json | Remove unused @wordpress/data dependency. |
| projects/packages/rtc/changelog/dotcom-17555-rtc-tracks-context | Add changelog entry for server-sourced Tracks context. |
| projects/packages/rtc/changelog/dotcom-17555-jetpack-rtc-blocked | Add changelog entry for new blocked Tracks event. |
| pnpm-lock.yaml | Lockfile update reflecting dependency removal. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
post_id/post_type (editor store) and wp_user_id (awareness) were unset when an event fired before those initialized — notably the room-limit block on a just-connected tab, which sent post_id=null, post_type=null, wp_user_id=undefined. Source post_id, post_type, and wp_user_id from the server-injected window.jetpackRtcNotices (present on both transports, available synchronously) in the shared recordRtcEvent, and inject userId (get_current_user_id) and postType server-side. Drops the @wordpress/data dependency. wp_user_id stays the site-local WP user id, matching the contributors id-space.
…m limit A client turned away by the room limit had its jetpack_rtc_join settle timer still fire ~3s later, emitting a spurious join (with an over-the-limit contributor_count). Guard the settle callback on isRoomLimitBreached() so a blocked client only emits jetpack_rtc_blocked.
The earlier filtered install (run while the registry was partially unreachable) over-pruned the lockfile, deleting ~2900 lines unrelated to this change. A clean `pnpm install` reduces the diff to the only real change: removing the @wordpress/data entry from the rtc importer.
- recordRtcEvent drops nullish context keys (Tracks serialises a present-but-nullish value as the string null/undefined, so omit them). - class-rtc.php computes get_post_type() once. - jetpack_rtc_blocked contributors deterministically exclude the blocked local client (reported via wp_user_id); getContributorIds gains an excludeLocal option, other tabs of the same user remain. - changelog entries end with a period.
7061688 to
77643b9
Compare
Fixes #
Proposed changes
jetpack_rtc_blockedTracks event, recorded when a client is turned away from a post because the per-room contributor limit was reached.notices/room-limit.ts— the point where the local client detects it is in the overflow set — firing once, for the turned-away client only, immediately before the providers are torn down. This runs inside the provider wrapper, which wraps providers on both transports, so it is transport-agnostic.getContributorIds,getLocalUserId) out oftrack-join.tsintotracking/awareness.tsso both the join and blocked events use them (pure refactor, no behaviour change).room-limit.ts(it had none), plus tests for the new module.Second of the RTC Tracks PRs. PR 1 added
jetpack_rtc_join; a follow-up will addjetpack_rtc_connection_error, then a final PR removes the inaccurate PingHub-onlyroom_peerspixel()telemetry these events replace (the existinglogConnectionEvent()connection logging stays).Related product discussion/links
Does this pull request change what data or activity we track or use?
Yes — this PR adds a new Tracks event. Adding the "[Status] Needs Privacy Updates" label.
The
jetpack_rtc_blockedevent is recorded in the WordPress.com block editor when a logged-in user is denied entry to a real-time collaboration room because the contributor limit was reached. Properties:transport—pinghuborhttp-pollingpost_id,post_type— the post being editedwp_user_id— the WordPress user id of the blocked (local) usercontributor_count— number of collaborators holding the room at the time of the block (the turned-away user is not counted)contributors— array of WordPress user IDs holding the room; the blocked/local user is excluded (reported separately viawp_user_id)is_admin,is_plan_owner— role flags for the blocked user (from the RTC notices config)blog_idis attached automatically by the analytics library. No new persistent storage is introduced; the event is sent to Tracks. Purpose: measure how often the RTC collaborator cap is hit and by whom.Known limitations
wp_user_id/contributorsare WordPress user IDs — WordPress.com ids on Simple sites, but site-local ids on Atomic/Jetpack (they differ from the wpcom id Tracks records as_ui), so they are only comparable within a singleblog_id. Documented intracking/awareness.ts.Testing instructions
Unit tests:
cd projects/packages/rtc && pnpm test— all suites should pass (28 tests).Functional (requires a WordPress.com environment with RTC enabled and a contributor limit in effect — i.e. a free-plan site where the cap applies; depends on wpcom Tracks + RTC infrastructure):
jetpack_rtc_blockedTracks beacon (filter the Network tab forpixel.wp.com) withtransport,wp_user_id,contributor_count,contributors(excluding the blocked user),is_admin,is_plan_owner.