}>
- { postHref ? (
-
- { post.title }
-
- ) : (
- // `.title` clamps to three lines, so keep the tooltip the link branch carries.
-
{ post.title }
- ) }
+
{ publishDate && (
@@ -157,8 +160,11 @@ export const LatestPostCard = ( { post }: LatestPostCardProps ) => {
* @return The widget content.
*/
function LatestPostReport() {
+ const { reportParams } = useWidgetRootContext();
const { post, isLoading, isFetching, isError, refetch } = useLatestPost();
+ const detailSearch = useMemo( () => pickReportDateParams( reportParams ), [ reportParams ] );
+
return (
- { post && }
+ { post && }
);
}
diff --git a/projects/packages/premium-analytics/widgets/latest-post/stories/latest-post-widget.stories.tsx b/projects/packages/premium-analytics/widgets/latest-post/stories/latest-post-widget.stories.tsx
index a5aa9fcb444a..bd8c71f5d259 100644
--- a/projects/packages/premium-analytics/widgets/latest-post/stories/latest-post-widget.stories.tsx
+++ b/projects/packages/premium-analytics/widgets/latest-post/stories/latest-post-widget.stories.tsx
@@ -25,6 +25,7 @@ import {
widgetDashboardWithWidgetArgTypes,
type WidgetDashboardWithWidgetControls,
} from '../../stories/widget-dashboard-with-widget';
+import { withStoryRouter } from '../../stories/with-story-router';
import { createStoryWidgetType } from '../../stories/create-story-widget-type';
import { withWidgetCanvas } from '../../stories/with-widget-canvas';
import LatestPostRender from '../render';
@@ -171,7 +172,7 @@ type Story = StoryObj< Partial< ComponentProps< typeof LatestPostRender > > >;
*/
export const Default: Story = {
render: renderLatestPost,
- decorators: [ withWidgetCanvas ],
+ decorators: [ withWidgetCanvas, withStoryRouter ],
};
/**
@@ -182,7 +183,7 @@ export const Loading: Story = {
render: () => renderLatestPostOnPreset( 'last-90-days' ),
// Off the shared autodocs page — path-keyed override; see forceStatsMockState.
tags: [ '!autodocs' ],
- decorators: [ withWidgetCanvas ],
+ decorators: [ withWidgetCanvas, withStoryRouter ],
beforeEach: () => forceLatestPostState( 'loading' ),
};
@@ -194,7 +195,7 @@ export const Loading: Story = {
export const Error: Story = {
render: () => renderLatestPostOnPreset( 'last-7-days' ),
tags: [ '!autodocs' ],
- decorators: [ withWidgetCanvas ],
+ decorators: [ withWidgetCanvas, withStoryRouter ],
beforeEach: () => forceLatestPostState( 'error' ),
};
@@ -205,7 +206,7 @@ export const Error: Story = {
export const Empty: Story = {
render: () => renderLatestPostOnPreset( 'last-365-days' ),
tags: [ '!autodocs' ],
- decorators: [ withWidgetCanvas ],
+ decorators: [ withWidgetCanvas, withStoryRouter ],
beforeEach: () => forceLatestPostState( 'empty' ),
};
diff --git a/projects/packages/premium-analytics/widgets/latest-post/style.module.css b/projects/packages/premium-analytics/widgets/latest-post/style.module.css
index a89269ac595f..10ffde846141 100644
--- a/projects/packages/premium-analytics/widgets/latest-post/style.module.css
+++ b/projects/packages/premium-analytics/widgets/latest-post/style.module.css
@@ -27,7 +27,10 @@
min-width: 0;
}
-.titleLink {
+/* `:any-link` so this beats `PostTitleLink`'s own `color: inherit` default
+ deterministically — as plain classes the two would tie and the winner would
+ depend on compiled stylesheet order. Same idiom as the post detail header. */
+.titleLink:any-link {
color: var(--wpds-color-foreground-content-neutral);
text-decoration: none;
}
diff --git a/projects/packages/premium-analytics/widgets/most-commented-posts/__tests__/most-commented-posts.test.tsx b/projects/packages/premium-analytics/widgets/most-commented-posts/__tests__/most-commented-posts.test.tsx
index 1614f6d8cd00..1bb66783b183 100644
--- a/projects/packages/premium-analytics/widgets/most-commented-posts/__tests__/most-commented-posts.test.tsx
+++ b/projects/packages/premium-analytics/widgets/most-commented-posts/__tests__/most-commented-posts.test.tsx
@@ -23,7 +23,11 @@ const posts = [
link: 'https://example.com/hello-world/',
},
{
- id: 43,
+ name: 'Untracked page',
+ comments: 8,
+ link: 'https://example.com/untracked/',
+ },
+ {
name: 'Unsafe permalink',
comments: 5,
link: 'javascript:alert(1)',
@@ -54,11 +58,22 @@ describe( 'MostCommentedPostsWidget', () => {
);
}
- it( 'links a post to its permalink in a new tab', async () => {
+ it( 'links a post to its detail page, carrying the permalink along', async () => {
+ renderWidget();
+
+ const link = await screen.findByRole( 'link', { name: 'Hello world' } );
+ const url = new URL( link.getAttribute( 'href' ) ?? '', 'https://example.com' );
+
+ expect( url.pathname ).toBe( '/post/42' );
+ expect( url.searchParams.get( 'post_url' ) ).toBe( 'https://example.com/hello-world/' );
+ expect( link ).not.toHaveAttribute( 'target', '_blank' );
+ } );
+
+ it( 'falls back to the permalink in a new tab when a post has no ID', async () => {
renderWidget();
- const link = await screen.findByRole( 'link', { name: /Hello world/ } );
- expect( link ).toHaveAttribute( 'href', 'https://example.com/hello-world/' );
+ const link = await screen.findByRole( 'link', { name: /Untracked page/ } );
+ expect( link ).toHaveAttribute( 'href', 'https://example.com/untracked/' );
expect( link ).toHaveAttribute( 'target', '_blank' );
} );
diff --git a/projects/packages/premium-analytics/widgets/most-commented-posts/render.tsx b/projects/packages/premium-analytics/widgets/most-commented-posts/render.tsx
index b4b7e71bd553..62caedeaaf7b 100644
--- a/projects/packages/premium-analytics/widgets/most-commented-posts/render.tsx
+++ b/projects/packages/premium-analytics/widgets/most-commented-posts/render.tsx
@@ -4,13 +4,12 @@
import { useStatsCommentsRows } from '@jetpack-premium-analytics/data';
import {
LeaderboardChart,
+ LeaderboardPostLabel,
ReportLink,
WidgetFooter,
WidgetRoot,
WidgetState,
- buildLeaderboardRow,
describeError,
- safeHttpUrl,
sharePercentage,
toMaxRows,
type LeaderboardChartData,
@@ -59,22 +58,12 @@ function MostCommentedPostsInner( { max }: MostCommentedPostsInnerProps ) {
const leaderboardData = useMemo< LeaderboardChartData >( () => {
const maxValue = Math.max( ...rows.map( row => row.value ), 0 );
- return rows.map( row => {
- // Post permalinks come from report data, so validate the scheme before
- // the row becomes a link.
- const href = safeHttpUrl( row.link );
-
- return {
- id: row.id,
- ...buildLeaderboardRow( {
- label: row.label,
- media: { kind: 'none' },
- action: href ? { kind: 'link', href } : { kind: 'static' },
- } ),
- currentValue: row.value,
- currentShare: sharePercentage( row.value, maxValue ),
- };
- } );
+ return rows.map( row => ( {
+ id: row.id,
+ label: ,
+ currentValue: row.value,
+ currentShare: sharePercentage( row.value, maxValue ),
+ } ) );
}, [ rows ] );
return (
@@ -121,8 +110,8 @@ function MostCommentedPostsInner( { max }: MostCommentedPostsInnerProps ) {
/**
* Most commented posts widget: the posts and pages that receive the most
- * comments, ranked by comment count. Each row links to the published post when
- * the report reports a permalink for it.
+ * comments, ranked by comment count. Each row opens the post detail page, and
+ * falls back to the published post when the report carries no post ID.
*
* One half of the Jetpack Stats "Comments" module; `jpa/most-commented-authors`
* covers the other. Both read the same `stats/comments` response through
diff --git a/projects/packages/premium-analytics/widgets/utm-insights/__tests__/use-utm-insights.test.tsx b/projects/packages/premium-analytics/widgets/utm-insights/__tests__/use-utm-insights.test.tsx
new file mode 100644
index 000000000000..d77afe2e50bb
--- /dev/null
+++ b/projects/packages/premium-analytics/widgets/utm-insights/__tests__/use-utm-insights.test.tsx
@@ -0,0 +1,88 @@
+/**
+ * External dependencies
+ */
+import {
+ useStatsUtm,
+ type ReportParams,
+ type StatsUtmComparisonItem,
+} from '@jetpack-premium-analytics/data';
+import { renderHook } from '@testing-library/react';
+/**
+ * Internal dependencies
+ */
+import useUtmInsights from '../use-utm-insights';
+
+jest.mock( '@jetpack-premium-analytics/data', () => ( {
+ useStatsUtm: jest.fn(),
+} ) );
+
+const mockUseStatsUtm = useStatsUtm as jest.MockedFunction< typeof useStatsUtm >;
+
+const reportParams = {
+ from: '2026-06-01',
+ to: '2026-06-30',
+ interval: 'day',
+} as ReportParams;
+
+describe( 'useUtmInsights', () => {
+ beforeEach( () => {
+ mockUseStatsUtm.mockReset();
+ } );
+
+ it( 'maps a UTM child post ID and URL into the widget drill-down row', () => {
+ const rows: StatsUtmComparisonItem[] = [
+ {
+ label: 'newsletter / email',
+ value: 18,
+ children: [
+ {
+ id: 41,
+ label: 'Landing page',
+ value: 12,
+ href: 'https://example.com/landing/',
+ page: '/stats/post/41',
+ actions: [],
+ children: null,
+ },
+ ],
+ },
+ ];
+
+ mockUseStatsUtm.mockReturnValue( {
+ comparisonRows: { rows, hasComparison: false },
+ hasComparison: false,
+ isLoading: false,
+ isFetching: false,
+ isError: false,
+ error: null,
+ refetch: jest.fn(),
+ } as never );
+
+ const { result } = renderHook( () =>
+ useUtmInsights( {
+ reportParams,
+ utmParam: 'utm_source,utm_medium',
+ max: 5,
+ } )
+ );
+
+ expect( result.current.data ).toEqual( [
+ expect.objectContaining( {
+ children: [
+ expect.objectContaining( {
+ postId: 41,
+ label: 'Landing page',
+ href: 'https://example.com/landing/',
+ } ),
+ ],
+ } ),
+ ] );
+ expect( mockUseStatsUtm ).toHaveBeenCalledWith(
+ expect.objectContaining( {
+ utmParam: 'utm_source,utm_medium',
+ max: 5,
+ } ),
+ { maxRows: 5 }
+ );
+ } );
+} );
diff --git a/projects/packages/premium-analytics/widgets/utm-insights/__tests__/utm-insights.test.tsx b/projects/packages/premium-analytics/widgets/utm-insights/__tests__/utm-insights.test.tsx
index aaff704c780c..b5db1bf8351f 100644
--- a/projects/packages/premium-analytics/widgets/utm-insights/__tests__/utm-insights.test.tsx
+++ b/projects/packages/premium-analytics/widgets/utm-insights/__tests__/utm-insights.test.tsx
@@ -2,25 +2,33 @@
* External dependencies
*/
import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
/**
* Internal dependencies
*/
import UtmInsightsWidget from '../render';
+import type { UtmInsightsRow } from '../use-utm-insights';
jest.mock( '@wordpress/route', () => jest.requireActual( '../../test-utils' ).mockWordPressRoute );
+let mockRows: UtmInsightsRow[] = [];
+
jest.mock( '../use-utm-insights', () => ( {
__esModule: true,
default: () => ( {
- data: [],
+ data: mockRows,
hasComparison: false,
isLoading: false,
isFetching: false,
- hasData: false,
+ hasData: mockRows.length > 0,
isError: false,
} ),
} ) );
+beforeEach( () => {
+ mockRows = [];
+} );
+
describe( 'UtmInsightsWidget', () => {
it( 'links to the UTM report', () => {
render( );
@@ -51,4 +59,55 @@ describe( 'UtmInsightsWidget', () => {
expect( screen.queryByRole( 'link', { name: 'See report' } ) ).not.toBeInTheDocument();
} );
+
+ it( 'links a drilled-in post to its detail page and carries the report window', async () => {
+ const user = userEvent.setup();
+ mockRows = [
+ {
+ label: 'jetpack-forms / email',
+ value: 30,
+ children: [
+ { postId: 12, label: 'Jetpack Forms', value: 20, href: 'https://example.com/forms/' },
+ ],
+ },
+ ];
+
+ render(
+
+ );
+
+ await user.click(
+ screen.getByRole( 'button', { name: 'View posts for jetpack-forms / email' } )
+ );
+
+ const titleLink = screen.getByRole( 'link', { name: 'Jetpack Forms' } );
+ expect( titleLink ).toHaveAttribute( 'href', expect.stringContaining( '/post/12' ) );
+ expect( titleLink ).toHaveAttribute( 'href', expect.stringContaining( 'from=2026-06-01' ) );
+ expect( titleLink ).not.toHaveAttribute( 'target', '_blank' );
+ } );
+
+ it( 'falls back to the public URL when a drilled-in post has no ID', async () => {
+ const user = userEvent.setup();
+ mockRows = [
+ {
+ label: 'jetpack-forms / email',
+ value: 30,
+ children: [
+ { postId: 0, label: 'Untracked page', value: 20, href: 'https://example.com/untracked/' },
+ ],
+ },
+ ];
+
+ render( );
+
+ await user.click(
+ screen.getByRole( 'button', { name: 'View posts for jetpack-forms / email' } )
+ );
+
+ const titleLink = screen.getByRole( 'link', { name: /Untracked page/ } );
+ expect( titleLink ).toHaveAttribute( 'href', 'https://example.com/untracked/' );
+ expect( titleLink ).toHaveAttribute( 'target', '_blank' );
+ } );
} );
diff --git a/projects/packages/premium-analytics/widgets/utm-insights/render.tsx b/projects/packages/premium-analytics/widgets/utm-insights/render.tsx
index 14ab2532da90..01893d7ee9b5 100644
--- a/projects/packages/premium-analytics/widgets/utm-insights/render.tsx
+++ b/projects/packages/premium-analytics/widgets/utm-insights/render.tsx
@@ -3,12 +3,13 @@
*/
import { useEffect, useMemo } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
-import { Stack, Text } from '@wordpress/ui';
+import { Text } from '@wordpress/ui';
import {
calculateDelta,
describeError,
getCombinedPeriodMax,
LeaderboardChart,
+ LeaderboardPostLabel,
ReportLink,
WidgetBackLink,
WidgetFooter,
@@ -135,13 +136,22 @@ function UtmInsightsInner( { utmDimension, max, showReportLink }: UtmInsightsInn
return activeData.map( ( item, index ) => {
const previousValue = item.previousValue;
+ const postRow = 'postId' in item ? item : null;
return {
id: `${ index }-${ item.label }`,
- label: (
-
+ label: postRow ? (
+
+ ) : (
+
{ item.label }
-
+
),
currentValue: item.value,
currentShare: sharePercentage( item.value, maxValue ),
diff --git a/projects/packages/premium-analytics/widgets/utm-insights/style.module.css b/projects/packages/premium-analytics/widgets/utm-insights/style.module.css
index 3500f82c9b30..5859a2c01fff 100644
--- a/projects/packages/premium-analytics/widgets/utm-insights/style.module.css
+++ b/projects/packages/premium-analytics/widgets/utm-insights/style.module.css
@@ -20,13 +20,24 @@
margin-block-end: 0;
}
+/* The UTM value rows. Post rows use `LeaderboardPostLabel` instead and take
+ only the inline-end inset below. */
.itemLabel {
+ display: flex;
+ align-items: center;
min-inline-size: 0;
padding-block: var(--wpds-dimension-padding-md);
padding-inline-start: var(--wpds-dimension-padding-sm);
padding-inline-end: var(--wpds-dimension-padding-lg);
}
+/* Keeps post-row text short of the value column, like `.itemLabel`. Doubled to
+ outrank the shared row's own `padding-inline` on specificity, because the two
+ are single classes in different CSS modules and would tie on order. */
+.itemLabelInset.itemLabelInset {
+ padding-inline-end: var(--wpds-dimension-padding-lg);
+}
+
.itemLabelText {
overflow: hidden;
white-space: nowrap;
diff --git a/projects/packages/premium-analytics/widgets/utm-insights/use-utm-insights.ts b/projects/packages/premium-analytics/widgets/utm-insights/use-utm-insights.ts
index d5b932d68b61..4a09322857eb 100644
--- a/projects/packages/premium-analytics/widgets/utm-insights/use-utm-insights.ts
+++ b/projects/packages/premium-analytics/widgets/utm-insights/use-utm-insights.ts
@@ -10,6 +10,7 @@ import type {
} from '@jetpack-premium-analytics/data';
export interface UtmInsightsChildRow {
+ postId: number;
label: string;
value: number;
previousValue?: number;
@@ -55,6 +56,7 @@ function getLabel( item: { label: unknown } ): string {
function toChildRow( item: StatsUtmComparisonTopPostItem ): UtmInsightsChildRow {
return {
+ postId: item.id,
label: getLabel( item ),
value: item.value,
previousValue: item.previousValue,