Skip to content

RTC: add jetpack_rtc_connection_error Tracks event - #49617

Merged
mmtr merged 2 commits into
trunkfrom
add/rtc-connection-error-tracks-event
Jun 15, 2026
Merged

mmtr merged 2 commits into
trunkfrom
add/rtc-connection-error-tracks-event

Conversation

@mmtr

@mmtr mmtr commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Fixes # N/A

Proposed changes

  • Add a jetpack_rtc_connection_error Tracks event, recorded the first time a client loses its real-time-collaboration sync connection (genuine, non-limit) in the WordPress.com block editor.
  • Skip the per-room-limit case (connection-limit-exceeded code / isRoomLimitBreached()) — it is already reported as jetpack_rtc_blocked, so recording it here too would double-count.
  • Hook the sync.providers filter at priority 30 (outside the room-limit wrapper at priority 20) and subscribe to the provider's status events, mirroring the existing withJoinTracking wrapper.

Why the provider status, not the error modal

The connection-error modal is shown via a Gutenberg filter whose API has changed across versions — the original editor.SyncConnectionErrorModal component filter (#76554) was replaced by the editor.isSyncConnectionErrorHandled value filter (#76853), and the component variant is additionally gated behind IS_GUTENBERG_PLUGIN (a no-op in production builds). The provider status is the transport-agnostic source of truth that drives that modal, so hooking it works regardless of which Gutenberg the site runs.

Notes on the implementation:

  • The PingHub transport emits a bare { status: 'disconnected' } with no error object, so an error is not required to record. error_code is included only when the transport supplies one (e.g. authentication-failed, protocol-mismatch); recordRtcEvent drops it when absent.
  • A clean teardown (navigating away, switching posts) also emits disconnected; a tearingDown guard set in the wrapper's destroy() keeps that from counting as an error.
  • Records at most once per provider (a flapping connection emits repeated disconnected events), ignores collection rooms (objectId === null), and runs on every RTC site regardless of the limit-notices feature flag — matching the room-limit and join-tracking wrappers.
  • Reuses the shared recordRtcEvent, so transport, post_id, post_type, and wp_user_id come from the server-injected window.jetpackRtcNotices config wired up in RTC: add jetpack_rtc_blocked Tracks event #49579 — no PHP changes needed.
  • Adds unit tests for the new module (suite goes 28 → 39).

Third of the RTC Tracks PRs. PR 1 (#49559) added jetpack_rtc_join; PR 2 (#49579) added jetpack_rtc_blocked. A final PR will remove 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_connection_error event is recorded in the WordPress.com block editor when a logged-in user editing a post loses the real-time-collaboration sync connection for a genuine (non-limit) reason. The per-room contributor-limit disconnection is deliberately excluded (reported separately as jetpack_rtc_blocked). Properties:

  • transport — pinghub or http-polling
  • post_id, post_type — the post being edited
  • wp_user_id — the WordPress user id of the affected user (site-local id; equals the WordPress.com id on Simple sites)
  • error_code — the sync ConnectionErrorCode when the transport supplies one (e.g. authentication-failed, connection-expired, protocol-mismatch, unknown-error); omitted for a bare disconnect (e.g. PingHub); connection-limit-exceeded is never recorded here

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 RTC connections fail for genuine (non-limit) reasons.

Testing instructions

Unit tests:

  • cd projects/packages/rtc && pnpm test — all suites should pass (39 tests).

Functional (requires a WordPress.com environment with RTC enabled; depends on wpcom Tracks + RTC infrastructure):

  • Open a post in the block editor on an RTC-enabled site and confirm collaboration connects.
  • Force a genuine connection failure — e.g. block the POST /wpcom/v2/rtc/pinghub-token request (PingHub) or the polling endpoint — so the editor surfaces the "Connection lost" modal.
  • Confirm a single jetpack_rtc_connection_error Tracks beacon fires (filter the Network tab for pixel.wp.com) with transport, post_id, post_type, wp_user_id, and — when the transport provides one — an error_code that is not connection-limit-exceeded.
  • Confirm a clean exit (navigating away / "Back to Posts" / switching posts) does not fire the event.
  • Confirm the per-room-limit block still fires only jetpack_rtc_blocked and not jetpack_rtc_connection_error.
  • Verify on both a PingHub (Simple) and an HTTP-polling (non-edge Atomic) site.

Record a jetpack_rtc_connection_error Tracks event on a genuine (non-limit)
sync connection error. The per-room-limit case is skipped — it is already
reported as jetpack_rtc_blocked, so counting it here too would double-count.

Hooks the sync.providers filter (priority 30, outside the room-limit wrapper)
and subscribes to provider status events, mirroring the join-tracking wrapper:
transport-agnostic, ignores collection rooms, records once per provider.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mmtr mmtr self-assigned this Jun 15, 2026
@mmtr mmtr added [Status] Needs Review This PR is ready for review. [Status] Needs Privacy Updates Our support docs will need to be updated to take this change into account labels Jun 15, 2026
@github-actions

github-actions Bot commented Jun 15, 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 (WordPress.com Site Helper), and enable the add/rtc-connection-error-tracks-event branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/rtc-connection-error-tracks-event

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 15, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

The PingHub transport emits a bare { status: 'disconnected' } with no
error object on connection loss, so requiring status.error meant the event
never fired there (the connection-lost modal showed but nothing tracked).

Record on any non-limit 'disconnected' status regardless of an error field,
and guard against the 'disconnected' a provider emits during a clean
teardown (navigation / switching posts) so it is not counted as an error.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mmtr
mmtr merged commit 61ece42 into trunk Jun 15, 2026
74 checks passed
@mmtr
mmtr deleted the add/rtc-connection-error-tracks-event branch June 15, 2026 14:49
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Rtc [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.

1 participant