feat(ai): add MCP activity log link and Tracks analytics events#48298
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! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 5 files.
Full summary · PHP report · JS report Coverage check overridden by
I don't care about code coverage for this PR
|
d0c7d6d to
fec715c
Compare
There was a problem hiding this comment.
Pull request overview
Adds an Activity Log entry point and instrumentation to the Jetpack AI MCP settings admin UI, so users can navigate to the site’s Activity Log and product can measure MCP settings usage.
Changes:
- Exposes an
activityLogUrlvalue to the AI admin React app and renders a new “Activity log” action card when MCP is enabled. - Adds new Tracks events for MCP settings page view, site-level toggle changes, and allowlist changes.
- Adds a Jetpack changelog fragment describing the feature.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| projects/plugins/jetpack/changelog/aiint-357-jetpack-ai-mcp-activity-log-and-metrics | Changelog entry for the Activity Log link + analytics events. |
| projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-ai-page.php | Computes and inlines activityLogUrl into jetpackAiSettings for the React app. |
| projects/plugins/jetpack/_inc/client/ai/main.jsx | Fires “settings viewed” Tracks event and passes activityLogUrl into the hub component. |
| projects/plugins/jetpack/_inc/client/ai/mcp/index.jsx | Adds site-level toggle Tracks event and renders the Activity Log action card. |
| projects/plugins/jetpack/_inc/client/ai/mcp/read.jsx | Adds allowlist Tracks events for per-tool and per-category toggles (read view). |
| projects/plugins/jetpack/_inc/client/ai/mcp/write.jsx | Adds allowlist Tracks events for per-tool and per-category toggles (write view). |
| projects/plugins/jetpack/_inc/client/ai/mcp/style.scss | Styling tweaks to support the new action card and link-row rendering. |
Comments suppressed due to low confidence (1)
projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-ai-page.php:99
- This page records Tracks events from the React bundle, but it doesn’t enqueue the Tracks client (
jp-tracks/ w.js) or injectwindow.jpTracksContext.blog_id(usually viaAutomattic\Jetpack\Connection\Initial_State::render_script). Without those, events may never be sent and/or won’t get ablog_idinjected. Consider mirroringclass.jetpack-react-page.phpby conditionally enqueuingjp-trackswhen connected & not offline, and rendering the Connection initial state for this handle.
$blog_id = Connection_Manager::get_site_id( true );
$site_suffix = ( new Status() )->get_site_suffix();
// On Atomic, jetpack-mu-wpcom replaces the cloud redirect with a direct WPCOM URL.
// Mirror that behaviour here so the activity log link resolves consistently.
$activity_log_url = ( new Host() )->is_woa_site()
? 'https://wordpress.com/activity-log/' . $site_suffix
: Redirect::get_url( 'cloud-activity-log-wp-menu', array( 'site' => $blog_id ? $blog_id : $site_suffix ) );
wp_enqueue_script(
'jetpack-ai-admin',
plugins_url( '_inc/build/jetpack-ai-admin.js', JETPACK__PLUGIN_FILE ),
$script_deps,
$script_version,
true
);
wp_set_script_translations( 'jetpack-ai-admin', 'jetpack' );
db10db1 to
bf3315b
Compare
- Add activity log link card to MCP hub (links to calypso-activity-log via siteRawUrl) - Expose siteRawUrl via jetpackAiSettings inline script using Status::get_site_suffix() - Add jp_mcp_settings_viewed on page load, jp_mcp_enabled_toggled on main toggle, and jp_mcp_allowlist_updated on per-tool and category bulk toggles Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Use cloud-activity-log-wp-menu redirect slug with blogId (same as Jetpack sidebar) so the link correctly resolves to wordpress.com on Atomic and cloud.jetpack.com on Jurassic Ninja / self-hosted - Add color/text-decoration resets to __connect-row for when it renders as <a> - Remove siteRawUrl from McpHub props and jetpackAiSettings (not needed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Compute activityLogUrl in PHP: use direct wordpress.com/activity-log/$domain on Atomic (matching jetpack-mu-wpcom sidebar behavior) and the cloud redirect for self-hosted, then pass it to JS via jetpackAiSettings - Add box-sizing: border-box to __connect-row so <a> width:100% + padding doesn't overflow the card (fixes chevron appearing outside container) - Add overflow: hidden via __action-card on Cards wrapping connect-rows so hover background respects the card's rounded corners Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… on Write row Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ty log URL - Rename all Tracks events from jp_ to jetpack_ prefix so @automattic/jetpack-analytics records them (jp_ events are silently dropped by the analytics library) - Use wp_parse_url(home_url(), PHP_URL_HOST) instead of get_site_suffix() for the Atomic activity log URL to avoid broken links on subdirectory installs where get_site_suffix() can return values containing '::' Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bf3315b to
914dcfb
Compare
|
I'll leave review of the code to someone more familiar with the feature, now that the CI is cleaned up. 🙂 |
sergeymitr
left a comment
There was a problem hiding this comment.
Works well 👍
It took me some time to find a way to come back from "Read" or "Write" screens, it wasn't obvious that you can click "AI" to come back.
So maybe we could add an arrow similar to WPCOM MCP settings to make it easier to go back to the main AI settings screen?
|
There's no established Jetpack admin pattern for a back arrow in breadcrumb, so going to merge this as is. Thanks for reviews. |
…mattic#48298) * feat(ai): add MCP activity log link and Tracks analytics events - Add activity log link card to MCP hub (links to calypso-activity-log via siteRawUrl) - Expose siteRawUrl via jetpackAiSettings inline script using Status::get_site_suffix() - Add jp_mcp_settings_viewed on page load, jp_mcp_enabled_toggled on main toggle, and jp_mcp_allowlist_updated on per-tool and category bulk toggles Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(ai): fix activity log link URL and anchor link styles - Use cloud-activity-log-wp-menu redirect slug with blogId (same as Jetpack sidebar) so the link correctly resolves to wordpress.com on Atomic and cloud.jetpack.com on Jurassic Ninja / self-hosted - Add color/text-decoration resets to __connect-row for when it renders as <a> - Remove siteRawUrl from McpHub props and jetpackAiSettings (not needed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(ai): fix activity log URL, chevron overflow, and hover corner bleed - Compute activityLogUrl in PHP: use direct wordpress.com/activity-log/$domain on Atomic (matching jetpack-mu-wpcom sidebar behavior) and the cloud redirect for self-hosted, then pass it to JS via jetpackAiSettings - Add box-sizing: border-box to __connect-row so <a> width:100% + padding doesn't overflow the card (fixes chevron appearing outside container) - Add overflow: hidden via __action-card on Cards wrapping connect-rows so hover background respects the card's rounded corners Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(ai): add overflow hidden to access card to fix hover corner bleed on Write row Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(ai): address Copilot review — rename Tracks events and fix activity log URL - Rename all Tracks events from jp_ to jetpack_ prefix so @automattic/jetpack-analytics records them (jp_ events are silently dropped by the analytics library) - Use wp_parse_url(home_url(), PHP_URL_HOST) instead of get_site_suffix() for the Atomic activity log URL to avoid broken links on subdirectory installs where get_site_suffix() can return values containing '::' Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(ai): rename remaining jp_ Tracks events to jetpack_ prefix Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: dognose24 <6869813+dognose24@users.noreply.github.com>
Fixes #
Proposed changes
https://wordpress.com/activity-log/{host}directly (matchingjetpack-mu-wpcom's sidebar behavior); on self-hosted/JN it uses thecloud-activity-log-wp-menuredirect slug. The resolved URL is passed to React asactivityLogUrlin thejetpackAiSettingsinline script.wp_parse_url( home_url(), PHP_URL_HOST )for the Atomic URL to avoid broken links on subdirectory installs whereget_site_suffix()can return values containing::.jetpack_mcp_settings_viewed— fires on page load when the user has MCP accessjetpack_mcp_enabled_toggled— fires when the site-level MCP toggle is changed, with{ enabled: bool }jetpack_mcp_allowlist_updated— fires on per-tool and category "Enable all" toggles, with{ tool_id?, enabled, tool_count?, view: 'read'|'write' }Related product discussion/links
Does this pull request change what data or activity we track or use?
Yes — adds three new Tracks events (
jetpack_mcp_settings_viewed,jetpack_mcp_enabled_toggled,jetpack_mcp_allowlist_updated) as specified in the PRD's Data Tracking Requirements section.Testing instructions
Activity log link:
wp-admin/admin.php?page=aihttps://wordpress.com/activity-log/{domain}; on self-hosted/JN it should openhttps://cloud.jetpack.com/activity-log/{blogId}Tracks events (requires MC/Tracks test environment):
wp-admin/admin.php?page=ai— confirmjetpack_mcp_settings_viewedfires oncejetpack_mcp_enabled_toggledfires with correctenabledvaluejetpack_mcp_allowlist_updatedfires withtool_id,enabled, andviewjetpack_mcp_allowlist_updatedfires withtool_countandview