Skip to content

Key Metrics data not clickable in the PDF #13370

Description

@wpdarren

Bug Description

The Key metric tiles in the PDF are not clickable E.g. Most popular content by pageviews or Top performing keywords - All of the tiles should behave the same as they do on the dashboard. When clicked the user should be either directed to Analytics, Search Console, AdSense, etc.

KM-PDF.mp4

Steps to reproduce

  1. Set up Site Kit with Analytics and AdSense.
  2. Generate the PDF on the menu.
  3. Observe the current behaviour where you cannot click on any of the data.

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • Each ranked row in a Key Metrics table tile in the PDF opens the same destination its dashboard row opens.
  • Page rows open the Analytics "All pages and screens" report filtered to that page, over the export's date range.
  • "Top performing keywords" rows open the Search Console search analytics report for an exact match on that keyword.
  • "Top earning content" rows open the Analytics report for that page.
  • Rows in a view-only export render as plain text with no link.
  • Key Metrics tiles whose dashboard rows are not links stay unlinked in the PDF.

Implementation Brief

  • In assets/js/components/pdf-export/shared-react-pdf-components/PDFMetricTileTable.tsx:
    • Add an optional primaryURL to PDFMetricTileTableRow.
    • Render the primary cell through PDFLink with href={ row.primaryURL }, keeping truncateContent on the text.
    • Remove the linked prop and the primaryLink style: PDFLink applies CONTENT_SECONDARY to a linked row and renders plain PDFTypography when href is empty.
  • In assets/js/components/KeyMetrics/key-metrics-pdf-tiles.js:
    • Add viewOnly to the getTileData parameters and pass it to each tile's extractor.
    • Set primaryURL on each row of KM_ANALYTICS_POPULAR_CONTENT, KM_ANALYTICS_POPULAR_PRODUCTS, KM_ANALYTICS_MOST_ENGAGING_PAGES, KM_ANALYTICS_LEAST_ENGAGING_PAGES, KM_ANALYTICS_TOP_RECENT_TRENDING_PAGES, KM_ANALYTICS_TOP_RETURNING_VISITOR_PAGES, KM_ANALYTICS_TOP_PAGES_DRIVING_LEADS and KM_ANALYTICS_ADSENSE_TOP_EARNING_CONTENT with getAllPagesReportURL( registry.select( MODULES_ANALYTICS_4 ), pagePath, pdfTableDates( dates ) ) from assets/js/modules/analytics-4/utils/page-report-url.ts, keyed by the row's page path rather than its title.
    • Set primaryURL on KM_SEARCH_CONSOLE_POPULAR_KEYWORDS rows with registry.select( MODULES_SEARCH_CONSOLE ).getServiceReportURL( { ...generateDateRangeArgs( pdfTableDates( dates ) ), query: !${ keyword } } ), the exclamation mark forcing an exact match as PopularKeywordsWidget does.
    • Return an empty primaryURL for every row when viewOnly is true.
    • Drop linked: true from all nine tile configs.
  • In assets/js/components/KeyMetrics/getPDFData.ts:
    • Destructure viewOnly from the loader parameters and pass it to getTileData alongside registry, dates and signal.
    • Extend the tile config type so getTileData accepts viewOnly.

Test Coverage

  • assets/js/components/pdf-export/shared-react-pdf-components/PDFMetricTileTable.test.tsx:
    • a row with a primaryURL renders its label as a link to that URL
    • a row without one renders the label as plain text
  • assets/js/components/KeyMetrics/key-metrics-pdf-tiles.test.js:
    • a page tile builds each row's URL from that row's page path and the single-period dates
    • the keywords tile builds an exact-match Search Console URL
    • the top earning content tile builds an Analytics page URL
    • every row's URL is empty when viewOnly is true
  • assets/js/components/KeyMetrics/getPDFData.test.ts:
    • viewOnly reaches getTileData

QA Brief

  • Follow steps to reproduce - verify links are clickable
    • View only users should not have clickable links but just text, replicating how it works in dashboard

Changelog entry

  • Fix key metrics click target in PDF report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0High priorityTeam SIssues for Squad 1Type: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions