Skip to content

Premium Analytics: Add a stacked bar view to the Devices widget - #54776

Open
chihsuan wants to merge 40 commits into
trunkfrom
change/pa-devices-stacked
Open

chihsuan wants to merge 40 commits into
trunkfrom
change/pa-devices-stacked

Conversation

@chihsuan

@chihsuan chihsuan commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Part of WOOA7S-1535

Proposed changes

  • Add a Bar chart option to the Devices widget. It stacks desktop, mobile and tablet views in one bar per day, week, month, quarter or year. The semi-circle stays the default.
  • Let readers turn on the previous period from the legend. A gray bar shows its total next to each stack, and the tooltip shows both periods with a Total row.
  • Add Download CSV to the bar view, with one row per day (or week, month…) and a column per device.
  • Stacked bar charts now show a Total row in their tooltip. This also adds one to the bar view of Requests by source on the AI tab.
  • Keep chart tooltips inside small cards. In a narrow card the dates shorten (Oct 29 – Nov 1, 2026) and wrap only if they still do not fit, and a tooltip near the edge no longer makes the chart jump or scroll.

The bars use a new option of the WordPress.com devices endpoint, which is already live. If the endpoint answers without per-day data, the widget shows an error instead of an empty chart.

Screen.Recording.2026-11-26.at.2.42.48.PM.mov

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

Setup: run Storybook (pnpm run storybook:dev in projects/js-packages/storybook), section Packages / Premium Analytics / Widgets / Devices.

Bar chart

  1. Open Bar Chart. Confirm one stacked bar per day, Desktop at the bottom, and Prev. 7 days dimmed in the legend.
  2. Click Prev. 7 days. Confirm a gray bar appears beside each stack.
  3. Hover a day. Confirm the tooltip lists Desktop, Mobile and Tablet for both periods, then a Total row that adds them up.
  4. Move the pointer across the bars near the card's right edge. Confirm the chart and its legend stay still, with no scrollbar flashing in the card.
  5. Click Mobile in the legend. Confirm the Mobile segments disappear and the gray bars get shorter too.

States

  1. Open Bar Chart Loading, Bar Chart Error and Bar Chart Empty. Confirm a bar skeleton, an error with Retry, and the generic "We couldn’t find results for this time period." empty state, as the semi-circle shows.

Download CSV

  1. Open Widget Dashboard With Widget and switch the Devices card to Bar chart. Click the download icon in the card footer. Confirm the file is named devices-over-time-<from>_<to>.csv and has a Date column plus one column per device, one row per day.
  2. Switch back to the semi-circle and download again. Confirm the file is devices-<from>_<to>.csv with Screen size and Share (%), as on trunk.

Unchanged

  1. Open Default and With Comparison. Confirm the semi-circle looks as on trunk.
  2. Open Packages / Premium Analytics / Widgets / Traffic chart and toggle Prev. in its legend. Confirm it still works and remembers the choice.
  3. Open Packages / Premium Analytics / Widgets / RequestsBySource, switch to the bar chart and hover a bar. Confirm the tooltip lists each source, then a Total row.

On a site with Stats device data

  1. On a site with Stats data, open Stats v2, switch the Devices widget to Bar chart from its chart type control, and pick Week in its interval menu. Confirm weekly stacks, and that their views add up to the Traffic summary's views for the same range.
  2. Switch back to the semi-circle. Confirm the interval menu disappears.
  3. Keep the Devices card one column wide in a window about 1280px wide, pick Week, turn on the previous period and hover a week that spans two months. Confirm both dates read like Oct 29 – Nov 1, 2026 on one line, with no scrollbar in the card.
  4. Hover the same week in the full-width Traffic summary. Confirm its tooltip still spells the months out in full.

@chihsuan chihsuan added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress labels Nov 11, 2026
@chihsuan chihsuan self-assigned this Nov 11, 2026
@github-actions

github-actions Bot commented Nov 11, 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 (Jetpack or WordPress.com Site Helper), and enable the change/pa-devices-stacked branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack change/pa-devices-stacked
bin/jetpack-downloader test jetpack-mu-wpcom-plugin change/pa-devices-stacked

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 github-actions Bot added [Package] Premium Analytics [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics [Plugin] Stats Data Docs labels Nov 11, 2026
@github-actions

github-actions Bot commented Nov 11, 2026 •

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!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: December 8, 2026
    • Code freeze: December 7, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Premium Analytics plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Stats Data plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@jp-launch-control

jp-launch-control Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 11 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/packages/data/src/hooks/use-stats-devices.ts 2/3 (66.67%) -33.33% 1 ❤️‍🩹
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-tooltip/dated-tooltip.tsx 20/21 (95.24%) -4.76% 1 ❤️‍🩹
projects/js-packages/charts/src/charts/private/pie-keyboard-navigation/use-pie-keyboard-navigation.ts 39/40 (97.50%) 0.13% 0 💚
projects/js-packages/charts/src/components/tooltip/private/bounded-tooltip.tsx 57/58 (98.28%) -0.03% 0 💚
projects/js-packages/charts/src/components/tooltip/xy-chart-tooltip.tsx 132/133 (99.25%) 0.01% 0 💚

4 files are newly checked for coverage.

File Coverage
projects/packages/premium-analytics/packages/icons/src/chart-half-ring/index.tsx 1/1 (100.00%) 💚
projects/packages/premium-analytics/widgets/devices/use-device-views-over-time.ts 23/23 (100.00%) 💚
projects/packages/premium-analytics/widgets/devices/widget.ts 3/3 (100.00%) 💚
projects/packages/premium-analytics/widgets/use-previous-period-shown.ts 7/7 (100.00%) 💚

Full summary · PHP report · JS report

…s-stacked

# Conflicts:
#	projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-comparative-bar/comparative-bar-chart.tsx
#	projects/packages/premium-analytics/packages/widgets-toolkit/src/index.ts
…s-stacked

# Conflicts:
#	projects/packages/premium-analytics/widgets/devices/render.tsx
List the legend item only while the total bar is drawn, draw no total
without a primary so the empty state shows, and warn that
comparisonSeriesItems is ignored in a stacked layout.
The total used the translated legend label as its key, so callbacks saw a
string that changed with the locale and a primary of the same name was
drawn in its place. Export COMPARISON_TOTAL_KEY and keep the label for
the tooltip and legend only.
…t's fixed key

Strip COMPARISON_TOTAL_KEY from the Devices tooltip instead of every key
outside the data, and stop handing a stacked chart comparisonSeriesItems,
which it ignores and now warns about.
Add --a8c-charts-color-comparison, mapped to the WPDS neutral-weak
foreground, and tone it to 3:1 against the background, as the grouped
and overlap layouts tone their palette colors.
…acked

# Conflicts:
#	projects/js-packages/charts/src/charts/bar-chart/index.ts
#	projects/js-packages/charts/src/charts/bar-chart/private/stack-layout.ts
#	projects/js-packages/charts/src/charts/bar-chart/private/use-bar-slots.ts
#	projects/js-packages/charts/src/charts/bar-chart/test/bar-chart-stacked.test.tsx
#	projects/js-packages/charts/src/charts/bar-chart/use-bar-colors.ts
#	projects/js-packages/charts/src/charts/bar-chart/use-bar-legend-items.ts
#	projects/js-packages/charts/src/providers/chart-context/stories/index.docs.mdx
#	projects/js-packages/charts/src/styles/chart-scope.scss
#	projects/packages/premium-analytics/packages/data/src/processing/stats/index.ts
#	projects/packages/premium-analytics/packages/data/src/queries/__tests__/stats-queries.test.ts
#	projects/packages/premium-analytics/packages/data/src/queries/index.ts
#	projects/packages/premium-analytics/packages/data/src/queries/stats-query.ts
#	projects/packages/premium-analytics/packages/widgets-toolkit/src/stories/mocks/register-stats-mocks.ts
@chihsuan
chihsuan marked this pull request as ready for review November 26, 2026 06:45
@chihsuan
chihsuan requested a review from a team as a code owner November 26, 2026 06:45
@chihsuan chihsuan added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Nov 26, 2026

@louwie17 louwie17 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.

Thanks @chihsuan, nice work on this! The bar view tested well on a local Docker site. I checked days and weeks with the previous period on and off, hiding Mobile, and the weekly stacks add up to the Traffic summary views for the same range. Keyboard focus also lands on the tooltip again after your latest push, same as trunk 👍

I did leave two inline comments, one around the weekly tooltip overflowing the card, which we should fix. The other is a small changelog nit.

Let me know what you think.

Co-reviewed and tested with Claude and Codex.

empty={ emptyState.empty }
renderLoading={ <BarChartSkeleton /> }
>
<ComparativeBarChart

@louwie17 louwie17 Nov 26, 2026 •

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.

With the card at its default half width and By weeks selected, hovering a bar with the comparison on adds a horizontal scrollbar under the chart and cuts off the previous period column. The tooltip is about 430px with the two date range headers, wider than the ~400px card, so BoundedTooltip can't fit it. By days fits fine.

Maybe we could cap the tooltip at the card width so it wraps, or use shorter range labels here, like "Oct 28 – Nov 1"?
Screenshot 2026-11-26 at 10 11 41

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch, fixed in dc71ac4 and 658b833. Narrow cards now use shorter dates.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Screen.Recording.2026-11-27.at.11.36.21.AM.mov

Significance: minor
Type: enhancement

Premium Analytics: Add a bar chart of views by device over time to the Devices widget, with the previous period's total beside each bar. Stacked bar tooltips, such as Requests by source, now end with a Total row.

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.

Small nit, should we also mention the tooltip fix here, and in the Stats and Premium Analytics plugin entries? Right now only the charts entry has it, and it shows in the dashboard cards.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good call, added it to the three plugin entries in dc71ac4.

Comment on lines +10 to +12
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
<Path d="M5.5 16.5a6.5 6.5 0 0 1 13 0" stroke="currentColor" strokeWidth="3" />
</SVG>

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.

I played a bit splitting the arc:

<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
		<Path
			d="M5.5 16.5A6.5 6.5 0 0 1 12.81 10.05M14.77 10.62A6.5 6.5 0 0 1 18.5 16.5"
			stroke="currentColor"
			strokeWidth="3"
		/>
	</SVG>
image

Maybe we can polish it a bit. Feel free to discard it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, the split reads more like a chart. Updated in e5d751a.

@chihsuan

Copy link
Copy Markdown
Member Author

Thanks for testing this so thoroughly @louwie17! The weekly tooltip now fits narrow cards with shorter dates, and the plugin entries mention the tooltip fix. Could you take another look?

…acked

# Conflicts:
#	projects/packages/premium-analytics/packages/data/src/processing/stats/index.ts

@louwie17 louwie17 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.

Thanks for the updates @chihsuan! The weekly tooltip now fits the narrow Devices card with the shorter dates, no more scrollbar, and wide cards still show the full dates. The changelog entries look good too, and the split half-ring icon reads nicely. LGTM 🚀

Co-reviewed and tested with Claude.

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

Docs Enhancement Changes to an existing feature — removing, adding, or changing parts of it [JS Package] Charts [Package] Premium Analytics [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics [Plugin] Stats Data RNA [Status] Needs Review This PR is ready for review. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants