Skip to content

Compute the Site Goals Key action rate from sessions with a Key action. - #14182

Open
jimmymadon wants to merge 43 commits into
developfrom
bug/14010-site-goals-key-action-rate
Open

jimmymadon wants to merge 43 commits into
developfrom
bug/14010-site-goals-key-action-rate

Conversation

@jimmymadon

@jimmymadon jimmymadon commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Related issue(s):

Relevant technical choices

Where this differs from the IB:

  • The rate moved out of processReports() into a new getKeyActionRates(), which requires the Key action sessions report, so no caller can keep the old formula.
  • The Key Metrics "Sales rate" and "Form completion rate" tiles (and their PDF tiles) and the Site Goals insight's conversion_rate use the same calculation. They all build the report with a shared buildKeyActionSessionsReportOptions(). The insight now makes 4 requests in its batch call, under GA4's limit of 5.
  • get_key_action_sessions_options() takes the goal type, like get_key_action_options(), not the event names.
  • The per-provider and per-form engagement requests, and the $custom_dimension parameter of get_engagement_options(), are removed, since nothing uses them anymore.
  • The stories use fixed site totals (1,250 and 1,100 sessions), because the generated mock data has only 14 sessions. 21 VRT reference images are updated.
  • headlineMetrics.ts (with its HeadlineMetricReportDates type) and getDimensionFiltersForEvents() moved from goal-drivers/ to site-goals/utils/, as the Site Goals widgets and Key Metrics tiles use them, not the goal drivers. These moves are in their own commits and change no behaviour.

Changes by file

Every Key action rate is now sessions with at least one Key action ÷ all site sessions. The sessions with a Key action come from a new report, the sessions metric filtered by event name. The site's sessions come from the engagement report, which no longer takes the tab filter.

Paths starting with site-goals/ are under assets/js/modules/analytics-4/components/site-goals/.

Shared JS helpers
  • site-goals/utils/headlineMetrics.ts (moved from goal-drivers/report-utils/)
    • New buildKeyActionSessionsReportOptions( dates, primaryEvent, breakdownFilter ): sessions with no dimensions, filtered by the Key action event(s) and the tab filter.
    • New private getPrimaryEventDimensionFilters(), shared with buildPrimaryEventReportOptions(), whose behaviour is unchanged.
    • Now holds the HeadlineMetricReportDates type, moved from goal-drivers/report-utils/types.ts.
  • site-goals/utils/getDimensionFiltersForEvents.ts (new): getDimensionFiltersForEvents(), moved unchanged from goal-drivers/utils.ts, with a new doc block.
  • site-goals/utils/reports.ts
    • New getKeyActionRates( keyActionSessionsReport, engagementReport ), returning currentRate, previousRate and currentSessions, with a rate of 0 when there are no sessions.
    • processReports() no longer returns the rates, only the counts, current sessions and engagement rates.
    • New exported getTotalsRows() (moved from the PDF code), private getTotalsMetric(), and getReportsToCheck( ...options ) (moved from OnlineStorePerformanceWidget.tsx).
  • Import updates only: goal-drivers/utils.ts, goal-drivers/report-utils/reportOptionsHelpers.ts, site-goals/utils/getSiteGoalsEventCountReportOptions.ts, site-goals/components/getKeyActionChartReportOptions.ts, and the Total sales, Total form completions, Sales engagement rate and Form completion engagement rate tiles and their tests.
Site Goals dashboard widgets
  • OnlineStorePerformanceWidget.tsx and LeadGenerationPerformanceWidget.tsx
    • Request the Key action sessions report with the current tab's filter, and include it in the loading and error checks.
    • The engagement report no longer takes the tab filter, so the "of X total sessions" subtitle is the same on every tab.
    • Counts still come from processReports(), while the rates come from getKeyActionRates().
    • Use the shared getReportsToCheck().
Key Metrics tiles
  • SalesRateWidget.tsx and FormCompletionRateWidget.tsx: request the Key action sessions report instead of the event count report, and use getKeyActionRates().
  • key-metrics-pdf-tiles.js: the same for the PDF tiles of Sales rate and Form completion rate. A tile is hidden when the Key action sessions report has no rows.
  • useAnalyticsReportsData.ts: doc comment wording only.
Dashboard PDF
  • pdf/reportOptions.ts: adds keyActionSessionsReportOptions, sessions filtered by eventName, with the breakdown dimension when there is one.
  • pdf/fetchSiteGoalsPDFReports.ts: requests it in the grouped and the aggregated sets, so 6 reports with a breakdown and 3 without.
  • pdf/shapeSiteGoalsPDFData.ts
    • The rate is each group's sessions with a Key action divided by the site's sessions, from the aggregated engagement report.
    • Each group's sessions is the site total, and its engagementRate still comes from the grouped engagement report.
    • getTotalsPair is replaced by the shared getTotalsRows.
Email report and Site Goals insight (PHP)
  • Site_Goals/Report_Options.php
    • New get_key_action_sessions_options( $goal_type, $custom_dimension = '' ).
    • get_engagement_options() loses $custom_dimension, so it always covers the whole site.
    • New private get_key_action_event_filter(), shared with get_key_action_options().
  • Email_Reporting/Report_Options.php: passes the new method through, and get_engagement_options() loses $custom_dimension.
  • Report_Request_Assembler.php
    • New payload keys SITE_GOALS_{ONLINE_STORE|LEAD}_KEY_ACTION_SESSIONS[_BY_PROVIDER|_BY_FORM]_KEY.
    • Removes SITE_GOALS_ENGAGEMENT_BY_PROVIDER_KEY and SITE_GOALS_ENGAGEMENT_BY_FORM_KEY.
    • Each active section asks for its Key action sessions report, split when it has a breakdown, plus the single site-wide SITE_GOALS_ENGAGEMENT_KEY.
  • Site_Goals_Section_Builder.php
    • The rate is each group's sessions with a Key action divided by the site's sessions, read by the new get_site_sessions().
    • sum_sessions() now takes any report with a sessions metric.
  • Insight_Payload_Builder.php
    • Adds the Key action sessions report to the batch, making 4 requests, under GA4's limit of 5.
    • conversion_rate is the sessions with a Key action divided by the site's sessions. conversions still counts events.
Tests, stories and VRT
  • JS tests
    • reports.test.ts (new): covers getKeyActionRates, processReports and getReportsToCheck.
    • headlineMetrics.test.ts (moved): adds cases for buildKeyActionSessionsReportOptions.
    • The widget tests add a store tab case and a form tab case: a tab's sessions with a Key action out of all site sessions.
    • SalesRateWidget, FormCompletionRateWidget and key-metrics-widgets tests: each session counts once.
    • The PDF tests, pdf/test-utils.ts and pdf/__fixtures__/index.ts cover the new report and the new expected rates.
  • Stories
    • New widgets/siteGoalsWidgetStoryReports.ts with helpers shared by both widgets' stories, using fixed site totals of 1,250 and 1,100 sessions.
    • Both widgets' stories use them.
  • PHP tests
    • The Report_Options, Report_Request_Assembler and Site_Goals_Section_Builder tests cover the new request and the new rate, with and without the plugin or form split.
    • The Insight_Payload_Builder tests cover the 4-report batch and the new conversion_rate.
    • Email_Reporting_Data_RequestsTest checks the new payload key.
  • VRT: 21 reference images updated, for 7 Site Goals widget stories at 3 sizes each. Only the rate tile's value and subtitle change.

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

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

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.
  • Ensure there are no unexpected significant changes to file sizes.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🤖 This comment is automatically updated by CI workflows. Each section is managed independently.

📚 Storybook for ab80b8e:

📦 Build files for ab80b8e:

🖼️ VRT report for ab80b8e:

🎭 Playwright reports for ab80b8e:

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the Key action rate calculation in the Analytics 4 Site Goals widgets (Lead Generation and Online Store) across the JS dashboard, PDF exports, and PHP email reporting. Instead of dividing the total event count by sessions, it introduces a new report that tracks unique sessions containing at least one key action event, preventing the rate from exceeding 100%. The feedback recommends simplifying the getTotalsMetric helper function in JS by removing a redundant type assertion and unnecessary optional chaining to improve code readability.

Comment on lines +107 to +115
function getValue( dateRangeSlug: string ) {
return (
parseFloat(
( totals as ReportRow[] )?.find?.(
makeFind( dateRangeSlug, 0 )
)?.metricValues?.[ metricIndex ]?.value ?? ''
) || 0
);
}

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.

medium

The type assertion as ReportRow[] is redundant because totals is already typed as an array of report rows (or defaults to []). Additionally, since totals is guaranteed to be an array, we can safely call .find directly without optional chaining (?.find?.). Simplifying this improves readability and avoids potential compilation issues if ReportRow is not explicitly imported in this file.

Suggested change
function getValue( dateRangeSlug: string ) {
return (
parseFloat(
( totals as ReportRow[] )?.find?.(
makeFind( dateRangeSlug, 0 )
)?.metricValues?.[ metricIndex ]?.value ?? ''
) || 0
);
}
function getValue( dateRangeSlug: string ) {
return (
parseFloat(
totals.find(
makeFind( dateRangeSlug, 0 )
)?.metricValues?.[ metricIndex ]?.value ?? ''
) || 0
);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done!

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 3.59 MB

ℹ️ View Unchanged
Filename Size Change
dist/assets/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.css 124 B 0 B
dist/assets/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.js 0 B 0 B 🆕
dist/assets/blocks/reader-revenue-manager/block-editor-plugin/index.js 47.1 kB 0 B
dist/assets/blocks/reader-revenue-manager/common/editor-styles.css 307 B 0 B
dist/assets/blocks/reader-revenue-manager/common/editor-styles.js 0 B 0 B 🆕
dist/assets/blocks/reader-revenue-manager/contribute-with-google/index.js 7.25 kB 0 B
dist/assets/blocks/reader-revenue-manager/contribute-with-google/non-site-kit-user.js 6.46 kB 0 B
dist/assets/blocks/reader-revenue-manager/subscribe-with-google/index.js 7.26 kB 0 B
dist/assets/blocks/reader-revenue-manager/subscribe-with-google/non-site-kit-user.js 6.46 kB 0 B
dist/assets/blocks/sign-in-with-google/editor-styles.css 84 B 0 B
dist/assets/blocks/sign-in-with-google/editor-styles.js 0 B 0 B 🆕
dist/assets/blocks/sign-in-with-google/index.js 18.5 kB 0 B
dist/assets/css/googlesitekit-admin-css-********************.min.css 79.1 kB 0 B
dist/assets/css/googlesitekit-adminbar-css-********************.min.css 12.7 kB 0 B
dist/assets/css/googlesitekit-authorize-application-css-********************.min.css 851 B 0 B
dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 9.09 kB 0 B
dist/assets/js/492-********************.js 970 B 0 B
dist/assets/js/959-********************.js 3 kB 0 B
dist/assets/js/1020-********************.js 1.03 kB 0 B
dist/assets/js/1212-********************.js 2.26 kB 0 B
dist/assets/js/1315-********************.js 3.08 kB 0 B
dist/assets/js/3022-********************.js 2.41 kB 0 B
dist/assets/js/3741-********************.js 3.84 kB 0 B
dist/assets/js/6174-********************.js 4.04 kB 0 B
dist/assets/js/7603-********************.js 61.5 kB 0 B
dist/assets/js/7792-********************.js 110 kB 0 B
dist/assets/js/9397-********************.js 477 kB 0 B
dist/assets/js/analytics-advanced-tracking-********************.js 428 B 0 B
dist/assets/js/googlesitekit-activation-********************.js 31.9 kB 0 B
dist/assets/js/googlesitekit-ad-blocking-recovery-********************.js 72.9 kB 0 B
dist/assets/js/googlesitekit-admin-pointers-********************.js 6.88 kB 0 B
dist/assets/js/googlesitekit-adminbar-********************.js 38.8 kB 0 B
dist/assets/js/googlesitekit-api-********************.js 9.93 kB 0 B
dist/assets/js/googlesitekit-block-tracking-********************.js 6.88 kB 0 B
dist/assets/js/googlesitekit-components-********************.js 7.02 kB 0 B
dist/assets/js/googlesitekit-consent-mode-********************.js 25.5 kB 0 B
dist/assets/js/googlesitekit-data-********************.js 1.84 kB 0 B
dist/assets/js/googlesitekit-datastore-forms-********************.js 8.6 kB 0 B
dist/assets/js/googlesitekit-datastore-location-********************.js 1.6 kB 0 B
dist/assets/js/googlesitekit-datastore-pdf-********************.js 1.23 kB 0 B
dist/assets/js/googlesitekit-datastore-site-********************.js 21.7 kB 0 B
dist/assets/js/googlesitekit-datastore-ui-********************.js 8.76 kB 0 B
dist/assets/js/googlesitekit-datastore-user-********************.js 26.9 kB 0 B
dist/assets/js/googlesitekit-entity-dashboard-********************.js 99.2 kB 0 B
dist/assets/js/googlesitekit-events-provider-contact-form-7-********************.js 1.27 kB 0 B
dist/assets/js/googlesitekit-events-provider-content-events-********************.js 3.16 kB 0 B
dist/assets/js/googlesitekit-events-provider-easy-digital-downloads-********************.js 651 B 0 B
dist/assets/js/googlesitekit-events-provider-mailchimp-********************.js 1.24 kB 0 B
dist/assets/js/googlesitekit-events-provider-ninja-forms-********************.js 1.26 kB 0 B
dist/assets/js/googlesitekit-events-provider-optin-monster-********************.js 1.28 kB 0 B
dist/assets/js/googlesitekit-events-provider-popup-maker-********************.js 1.35 kB 0 B
dist/assets/js/googlesitekit-events-provider-woocommerce-********************.js 895 B 0 B
dist/assets/js/googlesitekit-events-provider-wpforms-********************.js 1.3 kB 0 B
dist/assets/js/googlesitekit-feature-discovery-********************.js 40.2 kB 0 B
dist/assets/js/googlesitekit-features-********************.js 92.9 kB 0 B
dist/assets/js/googlesitekit-features-badge-********************.js 835 B 0 B
dist/assets/js/googlesitekit-i18n-********************.js 4.43 kB 0 B
dist/assets/js/googlesitekit-intents-********************.js 9.33 kB 0 B
dist/assets/js/googlesitekit-key-metrics-setup-********************.js 67.9 kB 0 B
dist/assets/js/googlesitekit-main-dashboard-********************.js 230 kB +254 B (+0.11%)
dist/assets/js/googlesitekit-metric-selection-********************.js 70 kB 0 B
dist/assets/js/googlesitekit-modules-********************.js 30.9 kB 0 B
dist/assets/js/googlesitekit-modules-ads-********************.js 62.6 kB 0 B
dist/assets/js/googlesitekit-modules-adsense-********************.js 158 kB 0 B
dist/assets/js/googlesitekit-modules-analytics-4-********************.js 321 kB +392 B (+0.12%)
dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 32.6 kB 0 B
dist/assets/js/googlesitekit-modules-reader-revenue-manager-********************.js 155 kB 0 B
dist/assets/js/googlesitekit-modules-search-console-********************.js 79.7 kB 0 B
dist/assets/js/googlesitekit-modules-sign-in-with-google-********************.js 41 kB 0 B
dist/assets/js/googlesitekit-modules-tagmanager-********************.js 35 kB 0 B
dist/assets/js/googlesitekit-notifications-********************.js 97.6 kB 0 B
dist/assets/js/googlesitekit-polyfills-********************.js 227 B 0 B
dist/assets/js/googlesitekit-settings-********************.js 91.4 kB 0 B
dist/assets/js/googlesitekit-splash-********************.js 75.6 kB 0 B
dist/assets/js/googlesitekit-user-input-********************.js 63.8 kB 0 B
dist/assets/js/googlesitekit-vendor-********************.js 315 kB 0 B
dist/assets/js/googlesitekit-vendor-lazy-pdf-********************.js 25.4 kB +751 B (+3.05%)
dist/assets/js/googlesitekit-widgets-********************.js 187 kB +156 B (+0.08%)
dist/assets/js/googlesitekit-wp-dashboard-********************.js 47.7 kB 0 B
dist/assets/js/runtime-********************.js 1.98 kB 0 B
dist/assets/js/sign-in-with-google-********************.js 1.35 kB 0 B

compressed-size-action

Moves the rate out of processReports() into getKeyActionRates(), which
requires the Key action sessions report, and uses it in the Site Goals
widgets, the Sales rate and Form completion rate Key Metrics tiles and
their PDF tiles.

@zutigrm zutigrm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @jimmymadon nice work. Left you some comments, let me know what you think

Comment on lines +2065 to +2066
// No rows means the report has no data, so don't render the tile.
if ( ! primaryEventReport?.rows?.length ) {
if ( ! keyActionSessionsReport?.rows?.length ) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This check can't hide the tile anymore. A site without purchases now gets a "Sales rate 0%" tile in the PDF, while the "Total sales" tile is still hidden.

The old report had the eventName dimension, so with no purchases it came back without rows. The new report has no dimension, and GA4 still returns one row per date range, with 0 in it. I checked it on a real property with no purchases: the new report came back with two rows of 0, the old one with none.

If we want to keep hiding the tile, we can check the values instead of the row count:

Suggested change
// No rows means the report has no data, so don't render the tile.
if ( ! primaryEventReport?.rows?.length ) {
if ( ! keyActionSessionsReport?.rows?.length ) {
// No Key action in either period means the report has no data, so don't render the tile.
if ( isZeroReport( keyActionSessionsReport ) ) {

with isZeroReport imported from @/js/modules/analytics-4/utils/is-zero-report. A test with the two 0 rows would cover it. The same applies to the "Form completion rate" tile below

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done!


// No rows means the report has no data, so don't render the tile.
if ( ! primaryEventReport?.rows?.length ) {
if ( ! keyActionSessionsReport?.rows?.length ) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same as above

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done!

sessions,
rate: toRate( total, sessions ),
total: toMetric( eventRows, EVENT_COUNT_INDEX ),
sessions: siteSessions,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

sessions is now the site total, but SiteGoalsBreakdownGroupPDF also uses it for the caption under the engagement rate (L261), and that rate is still the group's own. So in the PDF a form shows "Engagement rate 40%, of 900 total sessions", while 40% is the rate of the form's own 200 sessions (the '12' group in the lead fixtures). On the dashboard, the engagement tile of a tab shows the tab's own sessions (for example "of 29 total sessions" on the WooCommerce tab in the tabbed-breakdown-deactivated-plugin reference), so the PDF no longer matches it.

We can keep the group's own sessions for the engagement tile, something like engagementSessions: toMetric( engagementRows, SESSIONS_INDEX ) on the group, and use it for the engagement tile caption, while the rate tile keeps the site total

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done!

) {
$requests[ self::SITE_GOALS_ONLINE_STORE_PRIMARY_KEY ] = $this->report_options->get_online_store_primary_options();
$requests[ self::SITE_GOALS_ONLINE_STORE_PRIMARY_KEY ] = $this->report_options->get_online_store_primary_options();
$requests[ self::SITE_GOALS_ONLINE_STORE_KEY_ACTION_SESSIONS_KEY ] = $this->report_options->get_key_action_sessions_options( Conversion_Events_Provider::CATEGORY_ECOMMERCE );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When the section is split by plugin, Site_Goals_Section_Builder only reads the split sessions report, so this site-wide one is requested but never used. That's an extra Analytics request in every email for split sites. Before this PR the engagement report sat in an else for the same reason, we can do the same here, and assert in the split test that the key isn't requested. Same for the lead section at L255

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done!

* @param {Object} [breakdownFilter] Optional dimension filter scoping the report to a breakdown tab.
* @return {Object|undefined} The Analytics 4 `getReport` options, or `undefined` when there is no primary event.
*/
export function buildKeyActionSessionsReportOptions(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just a thought on the approach. GA4 gives the same number when sessions is a second metric on the existing Key action report. On a real property, one request with eventCount and sessions for a single event gave 634 events and 234 sessions, and the separate report this PR adds gave the same 234. With that we wouldn't need the extra report. Each Site Goals widget would stay at 2 requests per load instead of 3, the KM "Total sales" and "Sales rate" tiles would share one request again, and the Site Goals PDF stays at 4 requests per section instead of 6.

The catch is the lead report. It has the eventName dimension, and summing sessions over its rows counts a session with two lead events twice: on the same property, 243 sessions had either of two events, but the rows add up to 264. So the lead report would need to drop that dimension and read its counts from the totals.

I know the IB asks for a separate report, WDYT?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for testing this on a real property, it's a good find. I'd still keep the separate report in this PR, though:

  • For the lead report, dropping eventName and reading the totals only works without a breakdown. On a form tab, and in the PDF and email groups, the report is split by form and eventName, and the totals are site-wide, so we'd still count a session twice within a form. The lead report would need to drop eventName everywhere, and the email reads those eventName rows (filter_rows_by_event(), find_primary_event()) through options it shares with the store report. So lead would need its own options and readers.
  • The report options are also the cache keys in the tests and stories, so every mock of the Key action report would change too.

That would reshape the lead report in the same places this PR already changes, while the numbers are already right. The cost now is one extra request per widget load, and the PDF and email already batch theirs.

I'll open a follow-up issue for it, starting with a check that sessions stays deduplicated per form once eventName is dropped. WDYT?

} );
} );

it( 'never returns a rate above 1', () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

New and changed test titles should start with "should" (

Test title convention: `it(...)`/`test(...)` titles start with "should …" (e.g.
). These don't:

  • reports.test.ts: L59, L73, L83, L93, L110, L132
  • OnlineStorePerformanceWidget.test.tsx L2022, LeadGenerationPerformanceWidget.test.tsx L2054
  • shapeSiteGoalsPDFData.test.ts L160, fetchSiteGoalsPDFReports.test.ts L78, L86
  • key-metrics-widgets.test.js L543, L622

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done!

* The date range is the only dimension of the totals. A totals row without
* one counts as the current period.
*
* @since n.e.x.t

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is getTotalsPair moved from the PDF code, which had @since 1.187.0. We usually keep the original version and add the change:

Suggested change
* @since n.e.x.t
* @since 1.187.0
* @since n.e.x.t Renamed from `getTotalsPair` and moved from `shapeSiteGoalsPDFData`.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done!

groupedKeyActionSessionsReport: {
rows: [
...buildBreakdownReportRows( '12', [ '36' ], [ '17' ] ),
...buildBreakdownReportRows( '34', [ '18' ], [ '17' ] ),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Form 34 has 12 form completions in the current period and 9 in the previous one (L116), but 18 and 17 sessions with one, which GA4 can't return. The comment above says the opposite too. Something like [ '10' ], [ '8' ] would match

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done!

return array(
'conversions' => $conversions,
'conversion_rate' => $sessions > 0 ? round( $conversions / $sessions, 4 ) : 0.0,
'conversion_rate' => $sessions > 0 ? round( (int) $key_action_sessions / $sessions, 4 ) : 0.0,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

test_build__sends_a_conversion_rate_of_0_when_a_period_has_no_sessions has no key_action_sessions rows, so the rate there is 0 even without this $sessions > 0 check. Changing the check to $key_action_sessions > 0 still passes. Let's add a few sessions with a key action to that test so the 0 can only come from the missing site sessions

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done!

* Internal dependencies
*/
import { getDimensionFiltersForEvents } from '@/js/modules/analytics-4/components/site-goals/goal-drivers/utils';
import { getDimensionFiltersForEvents } from '@/js/modules/analytics-4/components/site-goals/utils/getDimensionFiltersForEvents';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is the same folder, so we can use ./getDimensionFiltersForEvents (

- Use relative paths only for files in the same directory or immediate subdirectories
). Same in getSiteGoalsEventCountReportOptions.ts L23

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done!

…ls-key-action-rate.

# Conflicts:
#	tests/phpunit/integration/Modules/Analytics_4/Site_Goals/Insight_Payload_BuilderTest.php
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/lead-generation-performance-widget/gathering-breakdown-data/large.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/lead-generation-performance-widget/gathering-breakdown-data/medium.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/lead-generation-performance-widget/gathering-breakdown-data/small.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/lead-generation-performance-widget/ready/large.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/lead-generation-performance-widget/ready/medium.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/lead-generation-performance-widget/ready/small.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/lead-generation-performance-widget/tabbed-breakdown-deactivated-plugin/large.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/lead-generation-performance-widget/tabbed-breakdown-deactivated-plugin/medium.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/lead-generation-performance-widget/tabbed-breakdown-deactivated-plugin/small.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/online-store-performance-widget/gathering-breakdown-data/large.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/online-store-performance-widget/gathering-breakdown-data/medium.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/online-store-performance-widget/gathering-breakdown-data/small.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/online-store-performance-widget/ready-purchase/large.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/online-store-performance-widget/ready-purchase/medium.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/online-store-performance-widget/ready-purchase/small.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/online-store-performance-widget/tabbed-breakdown-deactivated-plugin/large.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/online-store-performance-widget/tabbed-breakdown-deactivated-plugin/medium.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/online-store-performance-widget/tabbed-breakdown-deactivated-plugin/small.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/online-store-performance-widget/tabbed-breakdown-other-sources/large.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/online-store-performance-widget/tabbed-breakdown-other-sources/medium.png
#	tests/vrt/__screenshots__/modules/analytics-4/components/site-goals/online-store-performance-widget/tabbed-breakdown-other-sources/small.png
@jimmymadon jimmymadon added the VRT: Update reference images Apply this label to a PR to update the VRT reference images label Nov 24, 2026
@github-actions github-actions Bot removed the VRT: Update reference images Apply this label to a PR to update the VRT reference images label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Key Action Rate tiles in Key Metrics and Site Goal widgets display values exceeding 100%

3 participants