Skip to content

RTC: add jetpack_rtc_blocked Tracks event#49579

Open
dsas wants to merge 8 commits into
trunkfrom
dotcom-17555-jetpack-rtc-blocked
Open

RTC: add jetpack_rtc_blocked Tracks event#49579
dsas wants to merge 8 commits into
trunkfrom
dotcom-17555-jetpack-rtc-blocked

Conversation

@dsas

@dsas dsas commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #

Proposed changes

  • Add a jetpack_rtc_blocked Tracks event, recorded when a client is turned away from a post because the per-room contributor limit was reached.
  • Hook it into the existing overflow path in 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.
  • Extract the shared awareness helpers (getContributorIds, getLocalUserId) out of track-join.ts into tracking/awareness.ts so both the join and blocked events use them (pure refactor, no behaviour change).
  • Add the first unit tests for 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 add jetpack_rtc_connection_error, then a final PR removes the inaccurate PingHub-only room_peers pixel() telemetry these events replace (the existing logConnectionEvent() 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_blocked event 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:

  • transportpinghub or http-polling
  • post_id, post_type — the post being edited
  • wp_user_id — the WordPress user id of the blocked (local) user
  • contributor_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 via wp_user_id)
  • is_admin, is_plan_owner — role flags for the blocked user (from the RTC notices config)

blog_id is 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 / contributors are 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 single blog_id. Documented in tracking/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):

  • Open the same post in enough tabs/users to exceed the contributor limit.
  • The client that is turned away (sees the "Too many editors connected" modal) should fire a jetpack_rtc_blocked Tracks beacon (filter the Network tab for pixel.wp.com) with transport, wp_user_id, contributor_count, contributors (excluding the blocked user), is_admin, is_plan_owner.
  • Confirm clients that stay in the room do NOT fire the event.
  • Verify on both a PingHub (Simple) and an HTTP-polling (non-edge Atomic) site.

@dsas dsas added [Status] In Progress [Status] Needs Privacy Updates Our support docs will need to be updated to take this change into account labels Jun 12, 2026
@dsas dsas self-assigned this Jun 12, 2026
@github-actions

github-actions Bot commented Jun 12, 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 dotcom-17555-jetpack-rtc-blocked branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack dotcom-17555-jetpack-rtc-blocked
bin/jetpack-downloader test jetpack-mu-wpcom-plugin dotcom-17555-jetpack-rtc-blocked

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

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!

@jp-launch-control

jp-launch-control Bot commented Jun 12, 2026

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/rtc/src/class-rtc.php 125/152 (82.24%) 0.36% 0 💚

Full summary · PHP report · JS report

@dsas dsas marked this pull request as ready for review June 12, 2026 13:21
@dsas dsas requested a review from Copilot June 12, 2026 13:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_blocked Tracks event and hook it into the room-limit overflow path.
  • Refactor awareness roster helpers into tracking/awareness.ts and reuse them across join/blocked tracking.
  • Add unit tests for room-limit.ts and the new tracking modules; remove unused @wordpress/data dependency.

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

Comment thread projects/packages/rtc/src/js/tracking/tracks.ts Outdated
Comment thread projects/packages/rtc/src/class-rtc.php
Comment thread projects/packages/rtc/src/js/tracking/track-blocked.ts
Comment thread projects/packages/rtc/changelog/dotcom-17555-rtc-tracks-context Outdated
Comment thread projects/packages/rtc/changelog/dotcom-17555-jetpack-rtc-blocked Outdated
dsas added 8 commits June 12, 2026 15:54
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.
@dsas dsas force-pushed the dotcom-17555-jetpack-rtc-blocked branch 2 times, most recently from 7061688 to 77643b9 Compare June 12, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Rtc [Status] In Progress [Status] Needs Privacy Updates Our support docs will need to be updated to take this change into account [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants